Pages Menu
TwitterRssFacebook
Categories Menu

Posted by on Oct 14, 2013 in Blog, Programming | 1 comment

ASP.net Gridview error with Delete button – Must declare the scalar variable

Gridview

I have a Gridview on an ASP.net page.  I added the delete command to the SQL data source and told the gridview to “Enable Deleting.”

When the delete button is clicked I get an error – “Must declare the scalar variable @oid”.
OID in my case is the primary key of the table I’m wanting to be able to delete from.

GridviewError

The fix is very easy.  You want to go to the source view of the page where the gridview is at.
Add: DataKeyNames=”oid” to the asp:gridview code.  You need to change oid to the column name you are using to identify the record to delete.

GridviewFix

Now you should be able to delete to your heart’s content.

1 Comment

  1. Thanks.. My issue resolved

Post a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>