Hello all,

I need to update a field in a table with a value that contains dashes it. (e.g. 10-5-2). the field type is Text

The problem is that the field gets updated with "3" which is the result of the mathematical expression 10-5-3. And that's not what I want of Course.

My Code is as simple is this,

string updateCommand = String.Format("UPDATE MyTable SET MyTable.Code  = {0} WHERE MyTable.ID = {1}","10-5-3","124" )
                    OleDbCommand updateComm = new OleDbCommand(updateCommand, conn);

                    try
                    {
                        rowsAffectedNum += updateComm.ExecuteNonQuery();
                    }

How can I update the field with the string containing the dashes ?

You should place your value contains dashes in single quote '

string updateCommand = String.Format("UPDATE MyTable SET MyTable.Code  = '{0}' WHERE MyTable.ID = '{1}'","10-5-3","124" )
This question has already been answered. Start a new discussion instead.