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