Click to See Complete Forum and Search --> : Problem building oleDbSelectCommand1.CommandText string


MickeyDO
October 15th, 2005, 10:17 PM
Hi all,

I am working with C# to execute a query on an Access 2002 database. I have the connection and can get dataSets ... when I try to build this query, something goes wrong with the command string.


oleDbSelectCommand1.Connection = oleDbConnection1;
oleDbSelectCommand1.CommandText="SELECT DistanceTable." +
comboBox1.Text + " FROM DistanceTable " +
"WHERE (((DistanceTable.Cities) = " + "\""+comboBox2.Text +"\"" + "))";



The comboBoxes are filled from dataSets in the database. I had hoped my connection string would look like this:

"SELECT DistanceTable.Cleveland FROM DistanceTable WHERE(((DistanceTable.Cities) = "Detroit"))

However, it appears that I don't completely understand what is happening with the escape sequences in this case... when I run the code, I get no results and my string looks like this when I look in a quickwatch window at the oleDbSelectCommand1.CommandText :

"SELECT DistanceTable.Cleveland FROM DistanceTable WHERE(((DistanceTable.Cities) = \"Detroit\"))

If I write this string to a textBox... I do not see the backslash.

Any help would be appreciated.

Thanks,

Mike

MickeyDO
October 16th, 2005, 08:29 AM
Ahhh sorry... nothing like a good nights sleep to make a problem go away. I believe I had a problem with the database setup. Seeing the escape charactar in the string seems to be OK.. i just didn't know that.