Me中理解@变量时出现问题。我无法理解位于查询中的@variables。再次在更新查询
例如:
UPDATE tbSystems SET Systems = @Systems WHERE id = @id
我试图从具有AutoGenerateEditButton属性为True gridview的升级日期。这里是aspx文件:
<asp:GridView ID="gv1"
runat="server"
CellPadding="2"
DataKeyNames="id"
AutoGenerateDeleteButton="True"
AutoGenerateEditButton="True"
OnRowDeleting="gv1_RowDeleting"
OnRowDeleted="gv1_RowDeleted"
OnRowUpdating="gv1_RowUpdating">
</asp:GridView>
,这是该OnRowUpdating函数调用的函数:
protected void gv1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
switch (strType)
{
case "servers":
Response.Write("1");
break;
case "systems":
DS.UpdateCommand = "UPDATE tbSystems SET Systems = @Systems WHERE id = @id";
break;
case "itOwners":
Response.Write("3");
break;
case "systemOwners":
Response.Write("4");
break;
default:
break;
}
gv1.EditIndex = -1;
gv1.DataSourceID = DS.ID;
gv1.DataBind();
}
我一直在测试一两件事情没有任何成功。
试过:
- 系统添加到的DataKeyNames。这可以防止在Gridview中创建文本框。
- 做了一个系统参数添加到SqlDataSource。这给了我一个错误,告诉我系统变量已经存在。
- 获取Gridview编辑文本框中的信息没有任何成功。远离获得原始价值不是新的价值。
下面是我的一些问题:
- 如果只使用了的DataKeyNames识别主键?
- 如何获取由gridview的编辑选项创建的文本框中输入的信息?
- 如何获取或设置@variables中的信息?
谢谢,
它们是参数,请参见:[SqlParameter](https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlparameter(v = vs.110).aspx) – Habib
使用参数作为一种预防SQL注入的占位符。 –