Results 1 to 5 of 5

Thread: ADO Command SQL Statement w/ variable *Resolved*

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2003
    Location
    USA
    Posts
    102

    Question ADO Command SQL Statement w/ variable *Resolved*

    Sry if the title of the thread sucks but I am creating a command incode for my program and I am not sure if I wrote it quite right as i am not sure of how to add a variable to a SQL statement in VB so here is the code can you tell me if it is done right please.

    Thx in advance

    VB Code:
    1. With m_adoCommandAR
    2.         .CommandText = "SELECT Square_Name0, Square_Name1, Square_Name2, " & _
    3.                         "Square_Name3, Square_Name4, Square_Name5, " & _
    4.                         "Square_Name6, Square_Name7, Square_Name8, " & _
    5.                         "Square_Name9, FROM Areas WHERE Area_Name = " & _
    6.                         RoomName 'The variable
    7.        .CommandType = adCmdText
    8.        .ActiveConnection = m_adoConnection
    9.     End With
    Last edited by Tek; Oct 15th, 2003 at 05:44 AM.
    ===============
    Tek
    ===============

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Sep 2003
    Location
    USA
    Posts
    102
    I know I am annoying lol. However, I can do this no problem in PHP but never did a sql statement in vb b4.
    ===============
    Tek
    ===============

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: ADO Command SQL Statement w/ variable

    VB Code:
    1. With m_adoCommandAR
    2.         .CommandText = "SELECT Square_Name0, Square_Name1, Square_Name2, " & _
    3.                         "Square_Name3, Square_Name4, Square_Name5, " & _
    4.                         "Square_Name6, Square_Name7, Square_Name8, " & _
    5.                         "Square_Name9, FROM Areas WHERE Area_Name = '" & RoomName & "';"
    6.  
    7.  'The variable
    8.        .CommandType = adCmdText
    9.        .ActiveConnection = m_adoConnection
    10.     End With

    I just put a single quote around RoomName. If the variable is a string, then put single quotes around it, else if it's a numeric value, then don't put any quotes around it.

    HTh

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Sep 2003
    Location
    USA
    Posts
    102
    Thx Again
    ===============
    Tek
    ===============

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Anytime.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width