尝试删除或编辑时出现Gridview错误消息

时间:2014-02-23 01:16:43

标签: c# asp.net

我得到的错误信息是:

  

System.Data.OleDb.OleDbException:没有给出一个或多个必需参数的值。

我做了一点阅读,所以我进入了我的Boundfield并将所有内容都设置为只读。这没有解决它。我计算了我的参数,它们似乎匹配。所以我真的很困惑,因为这两个修复通常都是建议的。

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
    DeleteCommand="DELETE FROM [Students] WHERE (([Email] = ?) OR ([Email] IS NULL AND ? IS NULL))" 
    InsertCommand="INSERT INTO [Students] ([LastName], [FirstName], [MiddleInitial], [Phone], [Email], [GPA]) VALUES (?, ?, ?, ?, ?, ?)" 
    ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" 
    SelectCommand="SELECT * FROM [Students]" 
    UpdateCommand="UPDATE [Students] SET [LastName] = ?, [FirstName] = ?, [MiddleInitial] = ?, [Phone] = ?, [GPA] = ? WHERE (([Email] = ?) OR ([Email] IS NULL AND ? IS NULL))">
    <DeleteParameters>
        <asp:Parameter Name="Email" Type="String" />
    </DeleteParameters>
    <InsertParameters>
        <asp:Parameter Name="LastName" Type="String" />
        <asp:Parameter Name="FirstName" Type="String" />
        <asp:Parameter Name="MiddleInitial" Type="String" />
        <asp:Parameter Name="Phone" Type="String" />
        <asp:Parameter Name="Email" Type="String" />
        <asp:Parameter Name="GPA" Type="Double" />
    </InsertParameters>
    <UpdateParameters>
        <asp:Parameter Name="LastName" Type="String" />
        <asp:Parameter Name="FirstName" Type="String" />
        <asp:Parameter Name="MiddleInitial" Type="String" />
        <asp:Parameter Name="Phone" Type="String" />
        <asp:Parameter Name="GPA" Type="Double" />
        <asp:Parameter Name="Email" Type="String" />
    </UpdateParameters>
</asp:SqlDataSource>

1 个答案:

答案 0 :(得分:0)

在这两种情况下(编辑和删除),你都有一个没有值的神秘参数:

DeleteCommand =
  "DELETE FROM [Students] WHERE (([Email] = ?) OR ([Email] IS NULL AND ? IS NULL))" 

UpdateCommand =
  "UPDATE [Students] SET [LastName] = ?, [FirstName] = ?, [MiddleInitial] = ?, [Phone] = ?, [GPA] = ? WHERE (([Email] = ?) OR ([Email] IS NULL AND ? IS NULL))">

我要说你需要弄清楚为什么两个命令在它们的末尾都有OR ([Email] IS NULL AND ? IS NULL))。或者,如果您可以手动编辑您发布的代码,只需尝试删除该部分命令。