【问题标题】:Cannot find SQL variable in SqlDataSource在 SqlDataSource 中找不到 SQL 变量
【发布时间】:2011-11-08 17:09:29
【问题描述】:

我在 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>

【问题讨论】:

    标签: asp.net gridview sqldatasource


    【解决方案1】:

    我认为是这样的:

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

    应该是这样的:

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

    【讨论】:

    • 我更改了 DeleteCommand="DELETE FROM [Bookings] WHERE [ID] = @ID" ,我收到相同的结果.. 没有。如果我尝试一个有效的整数,例如 WHERE [ID] = 9",那么它无法引用 ID 的一些原因,删除命令有效。
    【解决方案2】:

    您按[programme name] 删除,从您的其他查询中看起来您想按[ID] 列删除。

    由于存在该列,因此您不会收到错误消息,也不会出现要删除的匹配项。将查询更改为:

     DELETE FROM Bookings WHERE ID=@ID
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-31
      • 2019-07-28
      • 2014-11-21
      • 1970-01-01
      相关资源
      最近更新 更多