I'm writing a program with C# to automatically insert data in a Navision database via ODBC. I am filling a DataTable-object by calling the OdbcDataAdapter.Fill() method. After changing some values, I want to update the original DB using OdbcDataAdapter.Update(). However this always results in:
ERROR [42000] [Simba][SimbaEngine ODBC Driver]UPDATE Item SET Location = ? WHERE ((No. << ??? >>= ?) AND ((? = 1 AND Location IS NULL) OR (Location = ?))) ERROR [42000] [Simba][SimbaEngine ODBC Driver]Syntax Error.
This is the code:
static void Main(string[] args)
{
DataTable Item = new DataTable();
OdbcConnection connection = new OdbcConnection("DSN=Navision Frank-Backup");
connection.Open();
OdbcDataAdapter adapter = new OdbcDataAdapter();
adapter.SelectCommand = new OdbcCommand("select \"No.\", \"Location\" from Item where \"No.\" = 'AA0182'", connection);
OdbcCommandBuilder builder = new OdbcCommandBuilder(adapter);
adapter.Fill(Item);
Item.Rows[0].BeginEdit();
Item.Rows[0]["Location"] = "SW";
Item.Rows[0].EndEdit();
adapter.UpdateCommand = builder.GetUpdateCommand();
adapter.Update(Item);
}
I'm hoping someone can help me out with that.
Edit: I just found out that if I set the update-command manually, using
adapter.UpdateCommand = new OdbcCommand("update Item set Location = 'SW' where \"No.\" = 'AA0182'");
It works perfectly fine. However I can't use that method because I need to change multiple records.