Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL querey from C# to Pervasive fails in two word column name 1

Status
Not open for further replies.

dghundt

Programmer
Apr 28, 2006
28
US
I am using Visual C# to access a Pervasive v8.6 database via ODBC interface. I can't find the right syntax to Select a column whose name is two words (white space in middle). If the column name is only one word, I'm fine.

Table is: Appointment
One column name is: Appt Date
One column name is: Length


This C# code works when I put it in my data reader
string queryString = "Select Length FROM Appointment";

But if I do this,
string queryString = "Select Appt Date FROM Appointment";
I get a syntax errors. I've tried all kinds of combinations, just not the right one, including:

string queryString = "Select" + "Appt Date" + "FROM Appointment";
string queryString = "Select" ApptDate AS [Appt Date] FROM Appointment";
string queryString = "Select" [Appt Date] = ApptDate FROM Appointment";

I can't change the column names without crashing the program I am trying to access.

If I go into the pervasive control center and enter this command, it works ok:
SELECT "Appt Date" FROM "Appointment"
If I browse the database with visual studio, I can see the data as well.


thanks for your help!
david
 
You need to surround the field name with double quotes in C# too.
For example:
Code:
string queryString = "SELECT \"Appt Date\" FROM Appointment"



Mirtheil
Certified Pervasive Developer
Certified Pervasive Technician
 
Thanks, your rock!

I used the following string which works well. As you point out, the \ prior to the quote is an escape character that tells C# to use the " literally instead of a delimeter for a string. I added \r\n which gave me a new line.

"SELECT \"Appt Date\", \"Appt Time\", \"Home Phone\"\r\nFROM Appointment
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top