How to generate the needed SQL statements to Update, Insert, Delete data in GridView?

你说的曾经没有我的故事 提交于 2019-12-02 07:21:52

Add the DeleteCommand to your SqlDataSource:

DeleteCommand="Delete from yourTable WHERE (ID = @ID)"

Like this:

<asp:SqlDataSource runat="server" DeleteCommand="Delete from yourTable WHERE (ID = @ID)">
    <DeleteParameters>
        <asp:Parameter Name="ID"></asp:Parameter>
    </DeleteParameters>
</asp:SqlDataSource>

EDIT: To make ASP.NET generate the DELETE command automatically for you without any code do the following steps:

  1. In the tasks window of your SqlDataSource, click Configure Data Source.
  2. Choose your data connection and Next.
  3. Make sure Specify a custom SQL statement or stored procedure checked and click Next.
  4. Select DELETE Tab and then click on the Query Builder, Select your table and then build your query by helping the Query Builder window. Your query should be look like this finally:

    Delete from yourTable WHERE (ID = @ID)
    
  5. And finally click Next And Finish.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!