Escaping special character

N

nicolasr

Hi,

I'm pretty new to ADO.NET and SQL and want to read in data from an Access
database. The problem is that the table I want to read data from has some
column names that contain a '-' charcter, f.e. 'Online-Kompass'.
When executing a SELECT command like
SELECT Online-Kompass FROM TheTable
I get a rather uninformative error but I assume it's because of the '-'
char.
Can anyone help how to handle this case?

thanks,
Nick
 
W

William Ryan

You can escape it with [Online-Kompass] but IMHO, hyphens in Table names is
nothing but trouble. Change it to Online_Kompass and never worry about it
again.

Cheers,

Bill
 
N

nicolasr

thanks Bill for the quick reply!
It seems to work great! I have other column names including '/' and it still
works.
Unfortunately I don't have influence on the table design. Since MS Access
allows those row names I can't prevent my users from naming them like
that...

thanks again,
Nick
 
P

Paul Clement

On Thu, 11 Sep 2003 04:46:14 +0200, "nicolasr" <nicolasrNOSPAMATSIGNgmx.net> wrote:

¤ thanks Bill for the quick reply!
¤ It seems to work great! I have other column names including '/' and it still
¤ works.
¤ Unfortunately I don't have influence on the table design. Since MS Access
¤ allows those row names I can't prevent my users from naming them like
¤ that...

Enclosing the field name within brackets will resolve the problem:

SELECT [Online-Kompass] FROM TheTable


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top