0

Hi,

I have the following code:

try
{
     var conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Database.accdb");
     var cmd = new OleDbCommand("UPDATE Resources SET Image=? WHERE ResourceName=?", conn);
     cmd.Parameters.Add("Image", OleDbType.VarChar).Value = listView.SelectedItems[0].Tag;
     cmd.Parameters.Add("ResourceName", OleDbType.VarChar).Value = _username;
     conn.Open();
     cmd.ExecuteNonQuery();
     conn.Close();
}
catch(Exception ex)
{
     Console.WriteLine(ex.Message);
}

I keep getting the following error message:
Syntax error in UPDATE statement.

I cant find the problem :( Anyone got any ideas?

2
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by JayWeb
0

You are doing incorrect update statement. On the right side of the equl mark you have the parameter, which you then have to specify in the command, like:

var cmd = new OleDbCommand("UPDATE Resources SET Image= @a WHERE ResourceName= @b", conn);
     cmd.Parameters.Add("@a", OleDbType.VarChar).Value = listView.SelectedItems[0].Tag;
     cmd.Parameters.Add("@b", OleDbType.VarChar).Value = _username;
0
try
    {
    var conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Database.accdb");
    var cmd = new OleDbCommand("UPDATE Resources SET Image= @a WHERE ResourceName= @b", conn);
    cmd.Parameters.Add("@a", OleDbType.VarChar).Value = listView.SelectedItems[0].Tag;
    cmd.Parameters.Add("@b", OleDbType.VarChar).Value = _username;
    conn.Open();
    cmd.ExecuteNonQuery();
    conn.Close();
    }
    catch(Exception ex)
    {
    Console.WriteLine(ex.Message);
    }

Using the above code, I still get the same error :(

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.