1

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>

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

5 Comments

yes i have, but that requires 2 parameters, which i need, to utilize for updating records in another table
you are using the same datakeynames in your stored procedure, right? I mean something like ... where BookCode = '@BookCode' and Quantity = '@Quantity' and quantity is your data key?
I had to put single quotes on the parameters like this '@Quantity' because I could not make comment with this directly @Quantity, so understand my code accordingly
Let me clear the whole concept, i have 2 tables "StudentLibrary (BookCode (Primary), Quantity)" and "StudentAllotment (StudAllotmentID (Primary and Identity), BookCode, Quantity)", now when the allotment is deleted i want to udpate the studentlibrary with the quantity of books deleted from allotment, so the gridviews datakey is StudAllotmentID, as i am showing allotments in the GridView.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.