From: Rick on
The following code in VS2005 with MS Access 2003 gives me an error : “No
Value given for one or more required parameters”
What am I doing wrong?

string sconnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; User
Id=; Password=; Data Source=C:\\Mydatabase.mdb";
string squeryString = "UPDATE MyTable SET Col1 = ?,Col2 = ?
WHERE ColId = ?";

int num = 19;
string str2 = txtRep.Text;
string str3 = txtCompanyName.Text;

try
{
using (OleDbConnection con = new
OleDbConnection(sconnectionString))
{
using (OleDbCommand cmd = new OleDbCommand(squeryString,
con))
{
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("Col1", str2);
cmd.Parameters.AddWithValue("Col2", str3);
cmd.Parameters.AddWithValue("ColId", num);

con.Open();
cmd.ExecuteNonQuery();
}
con.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}

From: Rick on
Nevermind, there was a typo in one of the fields causing the error.

"Rick" wrote:

> The following code in VS2005 with MS Access 2003 gives me an error : “No
> Value given for one or more required parameters”
> What am I doing wrong?
>
> string sconnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; User
> Id=; Password=; Data Source=C:\\Mydatabase.mdb";
> string squeryString = "UPDATE MyTable SET Col1 = ?,Col2 = ?
> WHERE ColId = ?";
>
> int num = 19;
> string str2 = txtRep.Text;
> string str3 = txtCompanyName.Text;
>
> try
> {
> using (OleDbConnection con = new
> OleDbConnection(sconnectionString))
> {
> using (OleDbCommand cmd = new OleDbCommand(squeryString,
> con))
> {
> cmd.CommandType = CommandType.Text;
> cmd.Parameters.AddWithValue("Col1", str2);
> cmd.Parameters.AddWithValue("Col2", str3);
> cmd.Parameters.AddWithValue("ColId", num);
>
> con.Open();
> cmd.ExecuteNonQuery();
> }
> con.Close();
> }
> }
> catch (Exception ex)
> {
> MessageBox.Show(ex.Message);
> }
>