I am calling a static function to replace a value in .accdb file; to find a value of oldOA, then replace it with newOA.
public static bool updateOA(string oldOA, string newOA)
{
...
command.Parameters.AddWithValue("@oldOA", oldOA);
command.Parameters.AddWithValue("@newOA", newOA);
command.CommandText = "SELECT [OA_ID] FROM [Operating_Authority_Table] WHERE [OA_Name] = [@oldOA]";
long value = long.Parse(command.ExecuteScalar().ToString());
command.Parameters.AddWithValue("@OA_ID", value);
command.CommandText = "UPDATE [Operating_Authority_Table] SET [OA_Name] = [@newOA] WHERE [OA_ID] = " + value;
try
{
command.ExecuteNonQuery();
message.show(1, "", "true");
return true;
}
catch
{
message.show(1, "", "false");
return false;
}
}
Initially i simply used:
command.CommandText = "UPDATE [OA_Table] SET [OA_Name] = [@newOA] WHERE [OA_Name] = [@oldOA]";
But i was told that I should get the OA_ID, which is the PK and update it from there, there resulting in the above code, but although the function still returns true, the value in the database still isn’t updated..
EDIT
command.CommandText = "UPDATE [Operating_Authority_Table] SET [OA_Name] = @newOA WHERE [OA_Name] = @oldOA";
I updated to this statement already, though it still returns true, the value does not get updated. Am i making any syntax mistakes?
My guess is this can solve your problem