2 Replies - 5111 Views - Last Post: 26 October 2008 - 03:37 PM Rate Topic: -----

#1 jens  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 67
  • View blog
  • Posts: 430
  • Joined: 09-May 08

sql CommandText from VB syntax problem

Post icon  Posted 26 October 2008 - 09:27 AM

This works fine if I run the question in a sql window in the sql server management studio:
SELECT * FROM tel RIGHT OUTER JOIN "namn-tel" ON tel.id="namn-tel".telid WHERE "namn-tel".namnid=@nID


NB that in order for this question to work I have to use the "-sign around the table names that contain a - -sign, i.e. namn-tel.

Now, how do I use this from VB as a sqlcommand.commandtext since the "-sign will end the string I'm sending to the DB?

I've tried using ' instead but it didn't work and I have searched some here and on the net for the combination " AND - AND commandtext.

/Jens

Is This A Good Question/Topic? 0
  • +

Replies To: sql CommandText from VB syntax problem

#2 magicmonkey  Icon User is offline

  • D.I.C Regular

Reputation: 106
  • View blog
  • Posts: 484
  • Joined: 12-September 08

Re: sql CommandText from VB syntax problem

Posted 26 October 2008 - 01:51 PM

To use a " in a string you double it up ""

Dim sql as String = "SELECT * FROM tel RIGHT OUTER JOIN ""namn-tel"" ON tel.id=""namn-tel"".telid WHERE ""namn-tel"".namnid=@nID"



However, it may be easier on the eyes to use brackets around the illegal names [ ].

Dim sql as String = "SELECT * FROM tel RIGHT OUTER JOIN [namn-tel] ON tel.id= [namn-tel].telid WHERE [namn-tel].namnid=@nID"


Was This Post Helpful? 1
  • +
  • -

#3 jens  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 67
  • View blog
  • Posts: 430
  • Joined: 09-May 08

Re: sql CommandText from VB syntax problem

Posted 26 October 2008 - 03:37 PM

Thank you! You might not believe it but I actually wrote it like that once but erased it immediately since I relized that it woldn't work... :crazy: :D Figured it would just make two strings and not work so I erased it without testing...

/Jens
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1