Hi,
I am new to c# coding, in my form i placed gridview and configured into access database and set advance option to edit,delete,update.
I can read all the values but i cant edit or delete the contents, showing error like below

"No value given for one or more required parameters.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

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

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. "

But the same one working in sql database, i cant find the solution. Can any one solve my problem plz....

Recommended Answers

All 4 Replies

No value given for one or more required parameters..

Error message says that your sql statement (query) has irrelevent column name. Show us your code please.

Encase your code in code-tags.

This is the sample page to test this problem, here i have placed two gridview one is connected with access database and another one connected with sql database,connected with sqldatabase is working but not access database.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
&nbsp;<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="empid"
DataSourceID="AccessDataSource1">
<Columns>
<asp:BoundField DataField="empid" HeaderText="empid" ReadOnly="True" SortExpression="empid" />
<asp:BoundField DataField="empname" HeaderText="empname" SortExpression="empname" />
<asp:BoundField DataField="position" HeaderText="position" SortExpression="position" />
<asp:BoundField DataField="jobband" HeaderText="jobband" SortExpression="jobband" />
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
</Columns>
</asp:GridView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/db1.mdb"
DeleteCommand="DELETE FROM [Table1] WHERE (([empid] = ?) OR ([empid] IS NULL AND ? IS NULL))"
InsertCommand="INSERT INTO [Table1] ([empid], [empname], [position], [jobband]) VALUES (?, ?, ?, ?)"
SelectCommand="SELECT * FROM [Table1]" UpdateCommand="UPDATE [Table1] SET [empname] = ?, [position] = ?, [jobband] = ? WHERE (([empid] = ?) OR ([empid] IS NULL AND ? IS NULL))">
<DeleteParameters>
<asp:Parameter Name="empid" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="empname" Type="String" />
<asp:Parameter Name="position" Type="String" />
<asp:Parameter Name="jobband" Type="String" />
<asp:Parameter Name="empid" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="empid" Type="String" />
<asp:Parameter Name="empname" Type="String" />
<asp:Parameter Name="position" Type="String" />
<asp:Parameter Name="jobband" Type="String" />
</InsertParameters>
</asp:AccessDataSource>
<br />
<br />
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataKeyNames="empid"
DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="empid" HeaderText="empid" ReadOnly="True" SortExpression="empid" />
<asp:BoundField DataField="empname" HeaderText="empname" SortExpression="empname" />
<asp:BoundField DataField="doj" HeaderText="doj" SortExpression="doj" />
<asp:BoundField DataField="email" HeaderText="email" SortExpression="email" />
<asp:BoundField DataField="pword" HeaderText="pword" SortExpression="pword" />
<asp:BoundField DataField="info" HeaderText="info" SortExpression="info" />
<asp:BoundField DataField="grade" HeaderText="grade" SortExpression="grade" />
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:attendanceConnectionString %>"
DeleteCommand="DELETE FROM [admin] WHERE [empid] = @empid" InsertCommand="INSERT INTO [admin] ([empid], [empname], [doj], [email], [pword], [info], [grade]) VALUES (@empid, @empname, @doj, @email, @pword, @info, @grade)"
SelectCommand="SELECT * FROM [admin]" UpdateCommand="UPDATE [admin] SET [empname] = @empname, [doj] = @doj, [email] = @email, [pword] = @pword, [info] = @info, [grade] = @grade WHERE [empid] = @empid">
<DeleteParameters>
<asp:Parameter Name="empid" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="empname" Type="String" />
<asp:Parameter Name="doj" Type="String" />
<asp:Parameter Name="email" Type="String" />
<asp:Parameter Name="pword" Type="String" />
<asp:Parameter Name="info" Type="String" />
<asp:Parameter Name="grade" Type="String" />
<asp:Parameter Name="empid" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="empid" Type="String" />
<asp:Parameter Name="empname" Type="String" />
<asp:Parameter Name="doj" Type="String" />
<asp:Parameter Name="email" Type="String" />
<asp:Parameter Name="pword" Type="String" />
<asp:Parameter Name="info" Type="String" />
<asp:Parameter Name="grade" Type="String" />
</InsertParameters>
</asp:SqlDataSource>

</div>
</form>
</body>
</html>

This is the sample page to test this problem, here i have placed two gridview one is connected with access database and another one connected with sql database,connected with sqldatabase is working but not access database.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
&nbsp;<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="empid"
DataSourceID="AccessDataSource1">
<Columns>
<asp:BoundField DataField="empid" HeaderText="empid" ReadOnly="True" SortExpression="empid" />
<asp:BoundField DataField="empname" HeaderText="empname" SortExpression="empname" />
<asp:BoundField DataField="position" HeaderText="position" SortExpression="position" />
<asp:BoundField DataField="jobband" HeaderText="jobband" SortExpression="jobband" />
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
</Columns>
</asp:GridView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/db1.mdb"
DeleteCommand="DELETE FROM [Table1] WHERE (([empid] = ?) OR ([empid] IS NULL AND ? IS NULL))"
InsertCommand="INSERT INTO [Table1] ([empid], [empname], [position], [jobband]) VALUES (?, ?, ?, ?)"
SelectCommand="SELECT * FROM [Table1]" UpdateCommand="UPDATE [Table1] SET [empname] = ?, [position] = ?, [jobband] = ? WHERE (([empid] = ?) OR ([empid] IS NULL AND ? IS NULL))">
<DeleteParameters>
<asp:Parameter Name="empid" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="empname" Type="String" />
<asp:Parameter Name="position" Type="String" />
<asp:Parameter Name="jobband" Type="String" />
<asp:Parameter Name="empid" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="empid" Type="String" />
<asp:Parameter Name="empname" Type="String" />
<asp:Parameter Name="position" Type="String" />
<asp:Parameter Name="jobband" Type="String" />
</InsertParameters>
</asp:AccessDataSource>
<br />
<br />
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataKeyNames="empid"
DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="empid" HeaderText="empid" ReadOnly="True" SortExpression="empid" />
<asp:BoundField DataField="empname" HeaderText="empname" SortExpression="empname" />
<asp:BoundField DataField="doj" HeaderText="doj" SortExpression="doj" />
<asp:BoundField DataField="email" HeaderText="email" SortExpression="email" />
<asp:BoundField DataField="pword" HeaderText="pword" SortExpression="pword" />
<asp:BoundField DataField="info" HeaderText="info" SortExpression="info" />
<asp:BoundField DataField="grade" HeaderText="grade" SortExpression="grade" />
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:attendanceConnectionString %>"
DeleteCommand="DELETE FROM [admin] WHERE [empid] = @empid" InsertCommand="INSERT INTO [admin] ([empid], [empname], [doj], [email], [pword], [info], [grade]) VALUES (@empid, @empname, @doj, @email, @pword, @info, @grade)"
SelectCommand="SELECT * FROM [admin]" UpdateCommand="UPDATE [admin] SET [empname] = @empname, [doj] = @doj, [email] = @email, [pword] = @pword, [info] = @info, [grade] = @grade WHERE [empid] = @empid">
<DeleteParameters>
<asp:Parameter Name="empid" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="empname" Type="String" />
<asp:Parameter Name="doj" Type="String" />
<asp:Parameter Name="email" Type="String" />
<asp:Parameter Name="pword" Type="String" />
<asp:Parameter Name="info" Type="String" />
<asp:Parameter Name="grade" Type="String" />
<asp:Parameter Name="empid" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="empid" Type="String" />
<asp:Parameter Name="empname" Type="String" />
<asp:Parameter Name="doj" Type="String" />
<asp:Parameter Name="email" Type="String" />
<asp:Parameter Name="pword" Type="String" />
<asp:Parameter Name="info" Type="String" />
<asp:Parameter Name="grade" Type="String" />
</InsertParameters>
</asp:SqlDataSource>

</div>
</form>
</body>
</html>

The number of '?' in your DeleteCommand and UpdateCommand does not match with the number of parameters defined in DeleteParameters amd UpdateParameters collection.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.