CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2008
    Location
    Step Into(F11)
    Posts
    465

    [RESOLVED] Sql Statement issue

    Can anyone tell me.why this sql statement is not working.Any help would be highly appreciated.
    here is the following statement.
    Code:
     strsql = " SELECT *" & _
      " From ALRAJHIBANK " & _
     " WHERE (((ALRAJHIBANK.ID)= & itemID & ))"
    Meanwhile this is working properly.
    Code:
    strsql = " SELECT *" & _
      " From ALRAJHIBANK " & _
     " WHERE (((ALRAJHIBANK.ID)=3))"

  2. #2
    Join Date
    Jan 2000
    Location
    Saskatchewan, Canada
    Posts
    595

    Re: Sql Statement issue

    strsql = " SELECT *" & _
    " From ALRAJHIBANK " & _
    " WHERE (((ALRAJHIBANK.ID)= " & itemID & "))"

  3. #3
    Join Date
    Jul 2009
    Location
    Brazil
    Posts
    25

    Re: Sql Statement issue

    When you use some variable inside one SQL statement, you should close quotes and concat with it.

    "SELECT * FROM " & sTESTE & " WHERE X = 1"

  4. #4
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Sql Statement issue

    Post number 2 has the correct solution. The second statement is not formated properly and as a result instead of placing the content of the itemId var into the statement it is placing & itemId &

    @firoz.raj When you run into an issue such as this you should either set a break point and look at the content of the strsql, or add a line to display this var in a message box or a debug.print statement. If you would have done any of these you would have most likely found your error in seconds.
    Last edited by DataMiser; July 25th, 2009 at 09:38 AM.

  5. #5
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: Sql Statement issue

    Also when dealing with SQL Statements within your VB code, it is always better to use parametrized queries. They give you more control and are compiled and secure.

    Take a look at this sample
    http://www.codeguru.com/forum/showpo...53&postcount=4

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

Featured