Results 1 to 6 of 6

Thread: hELP WITH LOADGRID QUERY

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2006
    Posts
    320

    hELP WITH LOADGRID QUERY

    I HAVE A SYNTAX PROBLEM THAT IS KICKING MY BUTT. I'M SURE THE ANSWER WILL EMBARASS ME BUT HER IT IS.

    Code:
     '****EXECUTE QUERY AND POPULATE GRID*****
    
            SQL.ExecQuery("SELECT VendorName, MachineNumber,Date, Description, Quantity, Price, Quantity * Price AS TOTAL " &
                        "FROM dbo.Parts " &
                        "WHERE MACHINENUMBER =cbxMachNo.Text") 'FAILS
    
            '  "WHERE MACHINENUMBER =13")                              'WORKS
            '  "WHERE [MACHINENUMBER] =" + cbxMachNo.Text)    'FAILS
    
            LOADGRID()
    I NEED TO BE ABLE TO USE THE cbxMachNo.text as the item for the where statement but I cannot get the sybtax correct for this line.

    Thanks

  2. #2
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,398

    Re: hELP WITH LOADGRID QUERY

    Maybe this:

    Code:
    "WHERE [MACHINENUMBER] = '" & cbxMachNo.Text & "'")

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,038

    Re: hELP WITH LOADGRID QUERY

    That seems unlikely. If the query with a number didn't require single quotes, why would it suddenly require single quotes when you get the value from some control? The field is clearly numeric for that first variation to work.

    1) Why did you use the square brackets on one and not on the other? It should make no difference, but it means you made two variations rather than one. Remove the square brackets unless you have a reason for them, or add them in the working test and confirm that it still works.

    2) What error are you getting?

    3) The first example will certainly fail, because you are not concatenating in the value from the control, but the string "cbxMachNo.Text" itself, which is not going to work. The second and third examples are written correctly, though I would use & rather than + in the third one. That should make no difference in this case, though.

    The third example you gave is the right one, so if that is failing, it makes me think that what is in the control is not what you think it is. Therefore, put a breakpoint on the line and have a look at what cbxMachNo.Text holds.
    My usual boring signature: Nothing

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2006
    Posts
    320

    Re: hELP WITH LOADGRID QUERY

    I had written this 6 months ago. with some help. I stepped away for a while due to health problems. I was aske to do some additional work making a grid to show monies spent on a piece of equipment. while looking around I believe I changed some of the query code by accident. What my re problem is to right some code (SQL) to add and sort some of the material out on a grid. that's my problem now. I am going to look for as many items to help me on the web and try before asking you guys for help.
    any pointers on where to go for info would be a help

    Thanks
    Bill

  5. #5
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,206

    Re: hELP WITH LOADGRID QUERY

    Yoour in the right place for help. You should start by answering Shaggy's questions.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: hELP WITH LOADGRID QUERY

    This is another of those extremely frequent cases where people are told that there's a syntax error in their SQL but they don't bother actually looking at that SQL. There's no syntax error in the VB code so why are you looking at that? You need to look at the actual SQL code being executed, i.e. the contents of the String that you're passing to that ExecQuery method. I'd wager that, if you'd done that in the first place, you'd never even have had to post this question, because the issue would have been obvious. As Shaggy said, the issue is almost certainly that the Text of the ComboBox is not what you think it is and you'd have seen that immediately if you'd actually looked.

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