我在GridView上有以下SqlDataSource。所有工作除删除功能外。
我做错了什么,没有给出错误但也没有结果。
如何解决这个问题?
<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 :(得分:4)
我想这个:
DELETE FROM [Bookings] WHERE [programme name] = @ID
应该是这样的:
DELETE FROM [Bookings] WHERE [ID] = @ID
答案 1 :(得分:1)
您可以[programme name]
从[ID]
列中删除您想要删除的其他查询。
由于该列存在,您不会收到错误,也不会删除匹配项。将查询更改为:
DELETE FROM Bookings WHERE ID=@ID