"Must declare the variable '@…..'." in GridView/DatailsView with M

P

PiotrF

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
should I change?
 
M

Mark Cushman

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..

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top