I am getting error "Input string was not in a correct format" when trying to update a table via the MySQL .NET connector.
The update statement works fine when run via MySQL workbench, but not via code and I am hoping someone can tell me why.
Code is:
MySqlCommand command = new MySqlCommand();
command.Connection = conn;
command.CommandText = "update fulfilled_shipments_data set addedCustomer=1 where amazonOrderId like '" + amazonOrderId + "%';";
command.ExecuteNonQuery();
I have tried both executing as a non query, and as ExecuteReader(); with no luck.
I am sure this is a simple mistake I am making, but I can't seem to find it for the life of me so any help would be greatly appreciated.
-- Edit -- I have tried the following with no luck:
MySqlCommand command = new MySqlCommand();
command.Connection = conn;
command.CommandText = "update fulfilled_shipments_data set addedCustomer=1 where amazonOrderId like '@amazonOrderId';";
command.Parameters.AddWithValue("@amazonOrderId", amazonOrderId);
also changed CommandText to:
command.CommandText = "update fulfilled_shipments_data set addedCustomer=1 where convert(varchar(50), amazonOrderId) like '" + amazonOrderId + "';";
and
command.CommandText = "update fulfilled_shipments_data set addedCustomer=1 where amazonOrderId = '@amazonOrderId';";
and
command.CommandText = "update fulfilled_shipments_data set addedCustomer=1 where amazonOrderId = @amazonOrderId;";
-- Resolution --
My resolution was actually found in another piece of code. After running through the debugger several times it became apparent that a MySqlConnection object was trying to be instantiated twice - with the same name etc. I removed the second instantiation and it has resolved the issue. It's too bad the error was misleading.
I appreciate everyone's responses as I feel they have made my code better and as such I have given +1's to Jon, Steve and Chris. Thanks for the help!
amazonOrderIdvariable already has some quotes around it? The MySQL update statement seems to work properly: sqlfiddle.com/#!2/bf794/1