I am trying to rename a field in my database through SQLite.net and am getting a syntax error. My SQL that I have tested is:
UPDATE candy SET name="Godiva" WHERE name="Sees";
and that works fine. I am using an SQLiteCommand with a CommandText of:
UPDATE candy SET @field_name=@new_name WHERE @field_name=@old_name;
and my code snippet that sets the values looks like this:
Connection.Open();
transaction = Connection.BeginTransaction();
UpdatePropertyQuery.Parameters.AddWithValue( "@field_name", "name");
UpdatePropertyQuery.Parameters.AddWithValue( "@old_name", "Sees");
UpdatePropertyQuery.Parameters.AddWithValue( "@new_name", "Godiva");
UpdatePropertyQuery.ExecuteNonQuery();
transaction.Commit();
Connection.Close();
I am no database expert, so from a newbie's standpoint, this seems like it should work, but maybe it's something with SQL in general that I'm not understanding. What's the correct way to do this, and can anyone explain why this approach wouldn't work?