简体   繁体   中英

unable to delete a record in Data grid view

error is coming while i'm tryin to delete a record from data source grid view. error message is giving ."Must declare the scalar variable "@regid"." my delete query "DELETE from tablename where reg_id=@regid"

plz give me some solution

thanks Churchill

Did you add the paramater to Delete Command??

Add like this:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="reg_id" CellPadding="4"
DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None" Style="z-index: 100;
left: 0px; position: absolute; top: 0px">
<DeleteParameters>
<asp:Parameter Name="@regid" Type="int32" />
</DeleteParameters>
</asp:GridView>

If your query is in stored procedure you must declare a variable to pass the value

ie

CREATE PROCEDURE usp_Delete
   @regid INT
AS

DELETE from tablename where reg_id=@regid

But if your query is hard-coded to the application you can concatinate the variable to the query like this

String sql = "DELETE from tablename where reg_id=" + regid.Text

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM