我创建了一个InsertTable
方法到AigsAuthorityLayer
表,但有一些事件依赖于权限范围。如果scope is ==
系统,这将是等于1,当scope is ==
到共享组ID值是GroupId = aigsDB.GetDefGroup(Convert.ToString(context.Session["GroupID"])).Rows[0]["lSharingGid"].ToString();
如果是scope == to group
,这将是C#插入到带有case语句的sql表中
authority = aigsDB.GetDefGroupUser(Convert.ToString(context.Session["UserId"].ToString()));
对于editFlg,如果是等于一,它将返回true,如果没有,假
CommonMethod.CheckLogin();
string sqlWord = CommonDB.CreateSqlString("AigsAuthorityLayer", "*", "", "", "");
context = HttpContext.Current;
CommonDB comDB = new CommonDB(connection);
try
{
string sql = "INSERT INTO AigsAuthorityLayer (lGid, LayerNo, lAuthority, IEditFlg) VALUES('{0}',{1}, {2},{3}')";
sql = sql.Replace("{0}", GroupId);
sql = sql.Replace("{1}", layerName.ToString());
sql = sql.Replace("{2}", authority.ToString());
sql = sql.Replace("{3}", editFlg.ToString());
comDB.Open();
comDB.AddNewRecord(sql);
{
comDB.Close();
comDB = null;
}
GroupId = "-1";
authority = "-1";
if (scope == "system")
{
return GroupId;
}
else if (scope == "sharing")
{
GroupId = aigsDB.GetDefGroup(Convert.ToString(context.Session["GroupID"])).Rows[0]["lSharingGid"].ToString();
}
else if (scope == "group")
{
authority = aigsDB.GetDefGroupUser(Convert.ToString(context.Session["UserId"].ToString()));
}
return true;
}
catch (Exception e)
{
throw logger.Error("InsertAigsAuthorityLayer", e);
}
finally
{
if (editFlg == "1")
{
return true;
}
else
{
return false;
}
comDB.Close();
comDB = null;
}
}
我的问题是,我不知道我这样做是正确:(任何人都知道如果这个代码是否正确?谢谢
为什么不使用[参数化查询](http://www.codinghorror.com/blog/2005/04/give-me-parameterized-sql-or-give-me-death.html)而不是字符串替换?顺便提一下,你的问题似乎有点不清楚。 –
@SonerGönül有一个重要的观点。你完全开放注入,并应改为参数化查询 –
我不知道该怎么做对不起@SonerGönül这只是第一次生病与C#工作。但是我的代码会工作吗? – Lyn