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

前端 未结 1 916
[愿得一人]
[愿得一人] 2021-01-27 03:10

I\'m using GridView along with SqlDataSource, for selecting, updating and deleting, and Detail

相关标签:
1条回答
  • 2021-01-27 03:33

    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.

    0 讨论(0)
提交回复
热议问题