<div>
<asp:GridView ID= "GridView1 "
DataSourceID= "SqlDataSource1 "
AutoGenerateDeleteButton= "true "
AutoGenerateEditButton= "true "
runat= "server ">
</asp:GridView>
<asp:SqlDataSource ID= "SqlDataSource1 "
runat= "server "
ProviderName= "System.Data.SqlClient "
ConnectionString= "Data Source=GOLDKING;Initial Catalog=Northwind;User ID=sa;Password=iq50628 "
UpdateCommand= "Update Customers SET CompanyName=@CompanyName,Address=@Address,City=@City,PostalCode=@PostalCode,Country=@Country where CustomerID = @CustomerID "
DeleteCommand= "Delete from Customers where CustomerID = @CustomerID "
SelectCommand= "SELECT [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] FROM [Customers] ">
<UpdateParameters>
<asp:Parameter Name= "CustomerID " />
<asp:Parameter Name= "CompanyName " />
<asp:Parameter Name= "Address " />
<asp:Parameter Name= "City " />
<asp:Parameter Name= "PostalCode " />
<asp:Parameter Name= "Country " />
</UpdateParameters>
</asp:SqlDataSource>
</div>
---
报错:必须声明变量 '@CustomerID '。 请问该如何解决,出现问题的原因是什么?
------解决方案--------------------------------------------------------
删除的情况,你必须指定gridview的DataKeyNames来唯一标示每一行,你这里应该是DataKeyNames= "CustomerID "
------解决方案--------------------------------------------------------
DataKeyNames的详细说明,自己查MSDN