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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

SQL and Global Variables.

  • 09-04-2005 2:37am
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 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, Registered Users 2 Posts: 542 ✭✭✭Hoochiemama


    Hey Bonkey,

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


  • Moderators, Politics Moderators Posts: 41,230 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, Registered Users 2 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: 41,230 Mod ✭✭✭✭Seth Brundle


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


  • Advertisement
  • Registered Users, Registered Users 2 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: 41,230 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, Registered Users 2 Posts: 542 ✭✭✭Hoochiemama


    That would be great! Cheers


  • Registered Users, Registered Users 2 Posts: 4,099 ✭✭✭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, Registered Users 2 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, Registered Users 2 Posts: 4,099 ✭✭✭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, Registered Users 2 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, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


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


  • Moderators, Politics Moderators Posts: 41,230 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, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    Was Option Explicit missing?


  • Moderators, Politics Moderators Posts: 41,230 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