somits
asked on
ERROR: No value given for one or more required parameters
Hi:
We're creating a web application with VS 2010 using Visual Basic.
We'd like to update an record in an access database table using GridView
For some reason, when we run the code, the program crashed with the following error: No value is given for one or more required parameters
We've checked again and again but could not find anything missing: each record in GridView has 3 fields: OrderID (text - primary key), Amount (double), and Tax (double). We wanted to update the field Amount of the 1st record in GridView. When we click "Update", it crashed.
If you've some idea why it crashed, please help.
We added the code below.
Thanks a lot,
Somits
//------------------------ ---------- ---------- ---------- ----------
<asp:Panel ID="Panel1" runat="server"
style="z-index: 1; left: 197px; top: 242px; position:
absolute; height: 57px; width: 531px">
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/ACCES SDB_8.accd b"
DeleteCommand="DELETE FROM [vb_access_db8_tb1] WHERE
(([OrderID] = ?) OR ([OrderID] IS NULL AND ? IS NULL))"
InsertCommand="INSERT INTO [vb_access_db8_tb1]
([OrderID], [Amount], [Tax]) VALUES (?, ?, ?)"
SelectCommand="SELECT * FROM [vb_access_db8_tb1]"
UpdateCommand="UPDATE [vb_access_db8_tb1] SET [Amount]
= ?, [Tax] = ? WHERE (([OrderID] = ?) OR ([OrderID] IS NULL AND ? IS
NULL))">
<DeleteParameters>
<asp:Parameter Name="OrderID" Type="String" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="OrderID" Type="String" />
<asp:Parameter Name="Amount" Type="Double" />
<asp:Parameter Name="Tax" Type="Double" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="Amount" Type="Double" />
<asp:Parameter Name="Tax" Type="Double" />
<asp:Parameter Name="OrderID" Type="String" />
</UpdateParameters>
</asp:AccessDataSource>
</asp:Panel>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False "
AutoGenerateDeleteButton=" True"
AutoGenerateEditButton="Tr ue" AutoGenerateSelectButton=" True"
DataKeyNames="OrderID" DataSourceID="AccessDataSo urce1"
style="z-index: 1; left: 204px; top: 354px; position:
absolute; height: 127px; width: 470px">
<Columns>
<asp:BoundField DataField="OrderID"
HeaderText="OrderID" ReadOnly="True"
SortExpression="OrderID" />
<asp:BoundField DataField="Amount" HeaderText="Amount"
SortExpression="Amount" />
<asp:BoundField DataField="Tax" HeaderText="Tax"
SortExpression="Tax" />
</Columns>
</asp:GridView>
We're creating a web application with VS 2010 using Visual Basic.
We'd like to update an record in an access database table using GridView
For some reason, when we run the code, the program crashed with the following error: No value is given for one or more required parameters
We've checked again and again but could not find anything missing: each record in GridView has 3 fields: OrderID (text - primary key), Amount (double), and Tax (double). We wanted to update the field Amount of the 1st record in GridView. When we click "Update", it crashed.
If you've some idea why it crashed, please help.
We added the code below.
Thanks a lot,
Somits
//------------------------
<asp:Panel ID="Panel1" runat="server"
style="z-index: 1; left: 197px; top: 242px; position:
absolute; height: 57px; width: 531px">
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/ACCES
DeleteCommand="DELETE FROM [vb_access_db8_tb1] WHERE
(([OrderID] = ?) OR ([OrderID] IS NULL AND ? IS NULL))"
InsertCommand="INSERT INTO [vb_access_db8_tb1]
([OrderID], [Amount], [Tax]) VALUES (?, ?, ?)"
SelectCommand="SELECT * FROM [vb_access_db8_tb1]"
UpdateCommand="UPDATE [vb_access_db8_tb1] SET [Amount]
= ?, [Tax] = ? WHERE (([OrderID] = ?) OR ([OrderID] IS NULL AND ? IS
NULL))">
<DeleteParameters>
<asp:Parameter Name="OrderID" Type="String" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="OrderID" Type="String" />
<asp:Parameter Name="Amount" Type="Double" />
<asp:Parameter Name="Tax" Type="Double" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="Amount" Type="Double" />
<asp:Parameter Name="Tax" Type="Double" />
<asp:Parameter Name="OrderID" Type="String" />
</UpdateParameters>
</asp:AccessDataSource>
</asp:Panel>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False
AutoGenerateDeleteButton="
AutoGenerateEditButton="Tr
DataKeyNames="OrderID" DataSourceID="AccessDataSo
style="z-index: 1; left: 204px; top: 354px; position:
absolute; height: 127px; width: 470px">
<Columns>
<asp:BoundField DataField="OrderID"
HeaderText="OrderID" ReadOnly="True"
SortExpression="OrderID" />
<asp:BoundField DataField="Amount" HeaderText="Amount"
SortExpression="Amount" />
<asp:BoundField DataField="Tax" HeaderText="Tax"
SortExpression="Tax" />
</Columns>
</asp:GridView>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Everything works correctly now.
Really appreciated,
Somits
Really appreciated,
Somits
ASKER
You're right. I didn't set the Primary Key field OrderID as Required in the Access table.
Therefore, VS generates more ? in the command statement of update.
Thanks so much for your help.
Somits