Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

SQL and Global Variables.

Options
  • 09-04-2005 3:37am
    #1
    Registered Users Posts: 542 ✭✭✭


    hey,

    i have a datagrid in part of my program. I want to refine the data printed from the database. im using the following SQL statement:

    select EmpID, Correct, Total, DateDone from UsersDone where ExamName = glo.userexam

    userexam is a global variable but this is not working. Can anyone tell me a way i can do this.

    im coding this in VB 6.0
    Cheers


Comments

  • Registered Users Posts: 15,443 ✭✭✭✭bonkey


    Something like
    sqlString = "select EmpID, Correct, Total, DateDone from UsersDone where ExamName = '" + glo.userexam + "'"
    
    is probably the basic idea of what you want to do.

    jc


  • Registered Users Posts: 542 ✭✭✭Hoochiemama


    Hey Bonkey,

    Thanks for the help. That didnt work! Any other suggestions?


  • Moderators, Politics Moderators Posts: 39,765 Mod ✭✭✭✭Seth Brundle


    1. what is the specific error you are getting?
    2. How have you defined your global variable?
    Global MyString as String
    Global MyInt as Integer
    Global MyDate as Date
    Global userexam as String
    
    3. reference the variable as
    sqlString = "select EmpID, Correct, Total, DateDone from UsersDone where ExamName = '" + userexam + "'"
    


  • Registered Users Posts: 542 ✭✭✭Hoochiemama


    1. Im not getting any error. when i leave the following out:
    where ExamName = '" + userexam + "'
    the information loads into the datagrid. But when i put that in the datagrid is blank.

    All my global variables are defined fine and all information is being passed into it. Ive stepped through the program to check this


  • Moderators, Politics Moderators Posts: 39,765 Mod ✭✭✭✭Seth Brundle


    does userexam have a value when it is passed to the SQL string?


  • Advertisement
  • Registered Users Posts: 542 ✭✭✭Hoochiemama


    yeah, when i stepped through it to check that. its weird. Also i tried setting the value of userexam to a local variable when the form loads and then i tried referencing the local variable instead but that didnt work!!


  • Moderators, Politics Moderators Posts: 39,765 Mod ✭✭✭✭Seth Brundle


    if you want email me the app and I will give it a look over (info AT kbannon DOT com) tomorrow


  • Registered Users Posts: 542 ✭✭✭Hoochiemama


    That would be great! Cheers


  • Registered Users Posts: 4,072 ✭✭✭muckwarrior


    Have you tried using a LIKE instead of = ? This might work if for some reason the value in the database isn't identical to the value in the variable.


  • Registered Users Posts: 542 ✭✭✭Hoochiemama


    Yeah i tried that too!! This is really starting to get at me. I have to have this done for monday for my FYP and this is the very last bit! But a couple of sections of my program depend on this working!


  • Advertisement
  • Registered Users Posts: 4,072 ✭✭✭muckwarrior


    The fact that it's workin without the where clause suggests that theres no record in the database corresponding to the value of your variable. If you haven't done already then double check to see that theres a record corresponding to the value of your variable. Try copy and pasting your query into Query Analyzer and run it substituting your variable with the value it should contain.


  • Registered Users Posts: 542 ✭✭✭Hoochiemama


    I tried that. nope, there is a corresponding record in the DB. Its definetly working. AAAGGGHHH, i love programming but things not working for no apparent reason pi$$ me off!! :eek:


  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    Cut and paste your code exactly and we'll see whats wrong.


  • Moderators, Politics Moderators Posts: 39,765 Mod ✭✭✭✭Seth Brundle


    the project was emailed to me and tbh it seems like there are errors all over the place and with many undeclared variables.
    Personally, I would start from scratch again and make it more simple and useable.


  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    Was Option Explicit missing?


  • Moderators, Politics Moderators Posts: 39,765 Mod ✭✭✭✭Seth Brundle


    [taking liberties with someone elses code here]
    no but Dimming the variables was! So much so that I gave up looking into the cause of the problem!


Advertisement