2

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

异常详细信息: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>
4

2 回答 2

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它应该可以工作

于 2013-04-25T23:06:38.793 回答
-1

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

于 2016-11-23T07:09:18.173 回答