Results 1 to 13 of 13

Thread: [RESOLVED]retrieving data from the database using SQL query

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2004
    Posts
    137

    [RESOLVED]retrieving data from the database using SQL query

    I have a form that retrieves data from the database and shows the record fields in text boxes...

    I have retrieved data using the properties window.... I called the datasource the reuiqred database and have assiged a datafield...this works expect it returns the first record in the table...I want it to return the data for a certain ID no (which is in textbox 'IDtxt' on the form)

    So I created the following query with in the command:

    SELECT * FROM customer WHERE (customerID = 'frmUpdate.IDtxt.Text')

    this does not work however if I change 'frmUpdate.IDtxt.Text ' to 2 it does work and returns the 2 record in the table...


    what am I doing wrong in the above query?????
    Last edited by pame1a; Aug 26th, 2004 at 08:07 PM.

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    Code:
    SQL = "SELECT * FROM customer WHERE (customerID = " & frmUpdate.IDtxt.Text & ")"
    TG
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2004
    Posts
    137
    the query doesnt wrk... i tried but nothing comes up on the form!!

    so i tried this:

    Code:
    WHERE (customerID = ' " & frmUpdate.IDtxt.Text & " ')
    and it still does not work.....can u actually call a text box in a query, i have tried calling ID = 2 that worked....

    PH
    Cheers

  4. #4
    Fanatic Member vb_dba's Avatar
    Join Date
    Jun 2001
    Location
    Somewhere aloft between the real world and insanity
    Posts
    1,016
    Is the ID field numeric or alpha numeric?

    Can you post the spot of code where you are defining your sql statement and then calling it?
    Chris

    Master Of My Domain
    Got A Question? Look Here First

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    Originally posted by pame1a
    the query doesnt wrk... i tried but nothing comes up on the form!!

    so i tried this:

    Code:
    WHERE (customerID = ' " & frmUpdate.IDtxt.Text & " ')
    and it still does not work.....can u actually call a text box in a query, i have tried calling ID = 2 that worked....

    PH
    Cheers
    No you can' call a text box in a query.... that's why I took it OUT, and appended it to the string that becomes the query.
    So, after executing the line I supplied, if yo udid a MsgBox SQL, you should have gotten a message that read
    SELECT * FROM customer WHERE (customerID = 2)
    Assuming 2 was in the text box.

    TG
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Mar 2004
    Posts
    137
    maybe thats the problem....

    What I've done is used a data environment using a command to create a query.....

    so the query appears in the datamember section of properties window!!
    Is this wrong? is this the only way to retrieve data from the database???


    Ive

  7. #7
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    Originally posted by pame1a
    maybe thats the problem....

    What I've done is used a data environment using a command to create a query.....

    so the query appears in the datamember section of properties window!!
    Is this wrong? is this the only way to retrieve data from the database???


    Ive

    Now it all makes sense. That is an importaint piece of information.
    Data environment is (in my opinion) an evil entity for just this reason.
    Suggestion - try reading the articles on ADO. They'll take you through the steps of establishign a conenction, retrieving data, and even updating data. Will provide more flexibility than the Data Environment.

    TG
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Mar 2004
    Posts
    137
    im using da ADO con now...

    i'm getting a timeout error.... wats going wrong??/

  9. #9
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Post the code in question to avoid the guess work




    Bruce.

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Mar 2004
    Posts
    137
    In form load i make a connection....

    then I have a sub fillfields()

    FName.Text = rs.Fields("FirstName")
    (trying it with one field first!!!)


    Private Sub Fill_Click ()
    Dim sql As string
    sql = "SELECT * FROM customer WHERE (customerID = '" & IDtxt.Text & "')"
    rs.Open sql, cn
    fillfields
    end sub


    problem is IDtxt is filled by a value from another form....I first had the fill_click sub within the form load sub ....however I think the IDtxt was not filled by then so it gave an error.

    The page works if i fill the text box instead of calling the value from another form.....

    PH

  11. #11
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    try this (as I had do do it in aprevious app); set the Focaus back to IDtxt just prior to the execution of the SQL statement.

    My guess is that the other Forms Control (TextBox?) may have the focus, and as such when the SQL execute IDtxt.Text it raises an error.




    Bruce.

  12. #12
    Hyperactive Member Vishalgiri's Avatar
    Join Date
    Oct 2003
    Location
    India
    Posts
    345
    what database engine you uses?
    Regards,
    Vishalgiri Goswami
    Gujarat, ( INDIA ).
    ---------------------

  13. #13
    PowerPoster Deepak Sakpal's Avatar
    Join Date
    Mar 2002
    Location
    Mumbai, India
    Posts
    2,424
    what database engine you uses?
    Does it really matters or r u just incrementing ur posts

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