PDA

Click to See Complete Forum and Search --> : Displaying Data from a DB


Gimpster
Nov 17th, 1999, 05:13 AM
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
corneslen@hotmail.com
ICQ# 47799046

Clunietp
Nov 17th, 1999, 10:00 AM
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

Gimpster
Nov 18th, 1999, 05:58 AM
Thank you very much! It works great!

------------------
Ryan
corneslen@hotmail.com
ICQ# 47799046

mocoo
Nov 18th, 1999, 01:43 PM
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