2

I am getting the following error message when trying to update customer details. I am using detailsview.

Exception Details: System.Data.OleDb.OleDbException: No value given for one or more required parameters.

I found here that this is normally related to a value which is Null or a zero-length string. So far so good, but how can I fix it?

Insert and Delete work fine. Even Update used to work, but something must have changed and I just cannot figure out what.

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>
John Saunders
  • 160,644
  • 26
  • 247
  • 397
Ron
  • 69
  • 2
  • 7
  • Is this SQL Server or Access? Note that SQL Server uses named parameters, Access uses indexed parameters. – Dai Apr 25 '13 at 22:55

2 Answers2

1

In your query

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

I count 12 parameter placeholders while your parameter list contains only 11 parameters
Particularly suspicious is the latest one. It is not possible to pass a column name as parameter.
What are you trying to do there? If you remove the AND ? IS NULL it should works

Steve
  • 213,761
  • 22
  • 232
  • 286
-1

removing (( AND ? IS NULL )) solve it