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?

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;
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 :(

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.