没有给出一个或多个必需参数的值。更新条目时

时间:2013-04-25 22:48:34

标签: asp.net visual-studio-2010 aspxgridview

尝试更新客户详细信息时收到以下错误消息。我正在使用详情视图。

  

异常详细信息:System.Data.OleDb.OleDbException:没有给出值   一个或多个必需参数。

我在这里发现这通常与Null或零长度字符串的值有关。到目前为止一切顺利,但我该如何解决呢?

插入和删除工作正常。甚至更新曾经工作,但一些事情必须改变,我只是无法弄清楚是什么。

UpdateCommand="UPDATE [Customers] SET [CompanyName] = ?, [ContactName] = ?, [ContactTitle] = ?, [Address] = ?, [City] = ?, [Region] = ?, [PostalCode] = ?, [Country] = ?, [Phone] = ?, [Fax] = ? WHERE (([CustomerID] = ?) OR ([CustomerID] IS NULL AND ? IS NULL))">

<UpdateParameters>
                <asp:Parameter Name="CompanyName" Type="String" />
                <asp:Parameter Name="ContactName" Type="String" />
                <asp:Parameter Name="ContactTitle" Type="String" />
                <asp:Parameter Name="Address" Type="String" />
                <asp:Parameter Name="City" Type="String" />
                <asp:Parameter Name="Region" Type="String" />
                <asp:Parameter Name="PostalCode" Type="String" />
                <asp:Parameter Name="Country" Type="String" />
                <asp:Parameter Name="Phone" Type="String" />
                <asp:Parameter Name="Fax" Type="String" />
                <asp:Parameter Name="CustomerID" Type="String" />
</UpdateParameters>

<FieldHeaderStyle CssClass="fieldheader"></FieldHeaderStyle>
            <Fields>
                <asp:BoundField DataField="CustomerID" HeaderText="CustomerID" ReadOnly="False" 
                    SortExpression="CustomerID" />
                <asp:BoundField DataField="CompanyName" HeaderText="CompanyName" 
                    SortExpression="CompanyName" />
                <asp:BoundField DataField="ContactName" HeaderText="ContactName" 
                    SortExpression="ContactName" />
                <asp:BoundField DataField="ContactTitle" HeaderText="ContactTitle" 
                    SortExpression="ContactTitle" />
                <asp:BoundField DataField="Address" HeaderText="Address" 
                    SortExpression="Address" />
                <asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
                <asp:BoundField DataField="Region" HeaderText="Region" 
                    SortExpression="Region" />
                <asp:BoundField DataField="PostalCode" HeaderText="PostalCode" 
                    SortExpression="PostalCode" />
                <asp:BoundField DataField="Country" HeaderText="Country" 
                    SortExpression="Country" />
                <asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone" />
                <asp:BoundField DataField="Fax" HeaderText="Fax" SortExpression="Fax" />
                <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
            </Fields>

2 个答案:

答案 0 :(得分:1)

在您的查询中

UPDATE Customers] SET [CompanyName] = ?, 
                      [ContactName] = ?, 
                      [ContactTitle] = ?, 
                      [Address] = ?, 
                      [City] = ?, 
                      [Region] = ?, 
                      [PostalCode] = ?, 
                      [Country] = ?, 
                      [Phone] = ?, 
                      [Fax] = ? 
WHERE (([CustomerID] = ?) OR ([CustomerID] IS NULL AND ? IS NULL))

我计算12个参数占位符,而参数列表只包含11个参数
特别可疑是最新的。无法将列名称作为参数传递 你想在那里做什么?如果您删除AND ? IS NULL它应该有效

答案 1 :(得分:-1)

删除((AND?IS NULL))解决它