1

I have the following SqlDataSource on a GridView. All works except for Delete Function.

What am I doing wrong , no error is given but no result either.

How can this be solved?

 <asp:SqlDataSource ID="BookingsSQL" runat="server" ConnectionString="<%$    ConnectionStrings:BookingsConnectionString %>"
 OldValuesParameterFormatString="original_{0}" ConflictDetection="OverwriteChanges"
 SelectCommand="SELECT [ID], [programme name] AS programme_name, [Start], [Finish], [Source], [Destination], [Comment] FROM [Bookings]"
 DeleteCommand="DELETE FROM [Bookings] WHERE [programme name] = @ID" InsertCommand="INSERT INTO [Bookings] ([programme name], [Start], [Finish], [Source], [Destination], [Comment]) VALUES (@programme_name, @Start, @Finish, @Source, @Destination, @Comment)"
 UpdateCommand="UPDATE [Bookings] SET [programme name] = @programme_name, [Start] = @Start, [Finish] = @Finish, [Source] = @Source, [Destination] = @Destination, [Comment] = @Comment WHERE [ID] = @ID">
 <DeleteParameters>
      <asp:Parameter Name="ID" Type="Int32" />
 </DeleteParameters>
 <InsertParameters>
      <asp:Parameter Name="programme_name" Type="String" />
      <asp:Parameter Name="Start" Type="DateTime" />
      <asp:Parameter Name="Finish" Type="DateTime" />
      <asp:Parameter Name="Source" Type="String" />
      <asp:Parameter Name="Destination" Type="String" />
      <asp:Parameter Name="Comment" Type="String" />
 </InsertParameters>
 <UpdateParameters>
      <asp:Parameter Name="ID" Type="Int32" />
      <asp:Parameter Name="Start" Type="DateTime" />
      <asp:Parameter Name="Finish" Type="DateTime" />
      <asp:Parameter Name="Source" Type="String" />
      <asp:Parameter Name="Destination" Type="String" />
      <asp:Parameter Name="Comment" Type="String" />
      <asp:Parameter Name="programme_name" Type="String" />
 </UpdateParameters>

0

2 Answers 2

4

I think this:

DELETE FROM [Bookings] WHERE [programme name] = @ID

should be this:

DELETE FROM [Bookings] WHERE [ID] = @ID
Sign up to request clarification or add additional context in comments.

1 Comment

I changed that DeleteCommand="DELETE FROM [Bookings] WHERE [ID] = @ID" , I receive the same result.. nothing . Some how its not able to refer to ID , if I try a valid integer eg WHERE [ID] = 9" the delete command works.
1

You delete by [programme name] where from your other queries it looks like you want to delete by the [ID] column.

Since that columns exists, you won't get an error but also no matches to delete. Change the query to:

 DELETE FROM Bookings WHERE ID=@ID

Comments

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.