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" )

Yes Ramy thanks, this indeed solved the problem

thanks again

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.