Results 1 to 4 of 4

Thread: Displaying Data from a DB

  1. #1

    Thread Starter
    Hyperactive Member Gimpster's Avatar
    Join Date
    Oct 1999
    Location
    Redmond, WA 98052
    Posts
    331

    Post

    I have looked for hours in the MSDN library to try to find out how you display the information stored in a SQL database. I am connecting to the database using an ADO connection. Here is an example of what I'm trying to do.

    Say I have a table called "Customers" and the table has three columns in it: "cust_id", "cust_lname", and "cust_fname". I want to be able to display these three tables on a form. However, this is where I am confused. I don't know if I need a flexgrid (because I've never used one, and don't really know what they're used for), or if I just use text boxes, or just what I need to have on the form. I also do NOT want to use the ADO Data Control, so I am going to have my own custom buttons to move around. I know how to program the buttons to move between recordsets, but I cannot figure out how to display the information in the current recordset. Please help, I'm going crazy.

    ------------------
    Ryan
    [email protected]
    ICQ# 47799046

  2. #2
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844

    Post

    OK Ryan, because you looked for HOURS in the MSDN Library, I'll help you out!

    you can display your results in whatever you want. If you plan on the user only seeing 1 record at a time, I would use a textbox or label. If you want them to see multiple records at a time, a grid would be the way to go. Here is some code to get your results w/o the data control.
    'declare objects
    dim cn as connection
    dim rs as recordset

    'instantiate connection object
    set cn = new connection

    'open connection to database with conn string
    cn.open <connectionstringhere>

    'execute SQL statement and return results to recordset
    set rs = cn.execute("Select * from MyTable where ID_FieldName = 123")

    'set textboxes to fields from record in recordset (the results you got from the query)
    Text1.text = rs.fields("cust_id").value
    text2.text = rs.fields("cust_lname").value
    text3.text = rs.fields("cust_fname").value

    'close connection to db
    cn.close

    'erase objects from memory
    set cn = nothing
    set rs = nothing

    Enjoy!

    Tom

  3. #3

    Thread Starter
    Hyperactive Member Gimpster's Avatar
    Join Date
    Oct 1999
    Location
    Redmond, WA 98052
    Posts
    331

    Post

    Thank you very much! It works great!

    ------------------
    Ryan
    [email protected]
    ICQ# 47799046

  4. #4
    New Member
    Join Date
    Nov 1999
    Posts
    8

    Post

    But wouldn't closing the connection and the recordset prevent you from changing to other retrieved records? (Assume textboxes linked to the recordset). I wan't to get a bunch of records in one recordset, and I wan't to close the connection afterwards, without losing the ability to navigate the recordset. How can I do it?
    Thank you

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