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注入的佔位符。 –