Groups | Blog | Home
all groups > asp.net datagrid control > august 2004 >

asp.net datagrid control : _M


PiotrF
8/14/2004 1:11:01 PM
I am testing ASP.NET 2.0 with MS SQL 2000. I get server error: "Exception
Details: System.Data.SqlClient.SqlException: Must declare the variable
'@KEY'" after record updating in GridView or DetailsView. I do not get this
message when I use MS ACCESS. I do not get this message with MS SQL when I do
not use DataKeyNames="KEY" in <asp:GridView ……/> or <asp:DetailsView …>. What
Mark Cushman
8/26/2004 3:40:24 PM
I am getting the same error even when I do a direct copy from MSDN material

MSDN CODE:
<asp:sqldatasource runat="server" id="MySource"
connectionstring="SERVER=(local);DATABASE=northwind;Integrated
Security=SSPI;"
datasourcemode="DataReader"
selectcommand="SELECT employeeid, firstname, lastname, photo
FROM employees"
updatecommand="UPDATE employees SET firstname=@firstname,
lastname=@lastname WHERE employeeid=@employeeid"
deletecommand="DELETE employees WHERE employeeid=@employeeid">
</asp:sqldatasource>

<asp:gridview runat="server" id="MyGridView" datasourceid="MySource"
datakeynames="employeeid" autogeneratecolumns="false"
autogenerateeditbutton="true" autogeneratedeletebutton="true">
<columns>
<asp:boundfield datafield="firstname" headertext="First" />
<asp:boundfield datafield="lastname" headertext="Last" />
<asp:imagefield datafield="photo" headertext="Picture" />
</columns>
</asp:gridview>

ERROR: System.Data.SqlClient.SqlException: Must declare the variable
'@employeeid'.

other code snippets from other sources produce similar results..

//////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\/////////////////////
///////\\\\\\\\\\\\\\\\\\\\\\\\


[quoted text, click to view]

AddThis Social Bookmark Button