Update Error in VS2005 with MS Access

R

Rick

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);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top