Search code examples
asp.netparameterssqldatasource

Delete parameters in SqlDatasource in asp.net


I have a Gridview which is connected with SqlDataSource for Data.
I have Edit and Delete built in functionality. I have passed the Stored Procedure for the SelectCommand.

Now I want to delete record and simultaneously update another table, now I do not get how to pass the values for the delete parameters in DeleteCommand

I also added DataKeyNames wherein I have provided the field (which is Primary Key and Auto Increment), but that too does not works. While deleting it simply says, Deleting is Supported, because no DeleteCommand is Specified.

I also tried creating a StoredProcedure for the delete task, but my StoredProcedure need to have some parameters so that I can update the records in another table.

Can anyone tell how could I pass the value for the Delete parameter.

UPDATED with SqlDataSource Markup

<asp:SqlDataSource ID="StudAllotmentDataSource" runat="server" 
    ConnectionString="<%$ ConnectionStrings:SiteSqlServer %>" 
    SelectCommand="user_GetStudAllotment" SelectCommandType="StoredProcedure" DeleteCommand="user_DeleteAllottedStudBook" DeleteCommandType="StoredProcedure">
   <DeleteParameters>
        <asp:Parameter Name="BookCode" Type="String" /> 
        <asp:Parameter Name="Quantity" Type="String" /> 
    </DeleteParameters>
</asp:SqlDataSource>

Solution

  • Did you specify DeleteCommand as your stored procedure in the sqlserverdatasource?