tchous
asked on
Simple ado connection to a database
I want to create a simple ado connection to a database.. I have previously used ASP to do this, now we are creating a VB application in which I never had done this..
here is my ASP code:
dim getdata
getdata = "Select ticket_number from ticketdetails"
myDSN="DSN=ardata;
set conntemp=server.createobje ct("adodb. connection ")
conntemp.open myDSN
set rstemp=conntemp.execute(ge tdata)
Now I am looking at the easiest way to get this accomplished in vb without using the ADODC objects.. hopefully something similar to the way I do it above.. If you know of a better way I should be doing this other than odbc adn recordsets, I am open to suggestions..
Thanks
here is my ASP code:
dim getdata
getdata = "Select ticket_number from ticketdetails"
myDSN="DSN=ardata;
set conntemp=server.createobje
conntemp.open myDSN
set rstemp=conntemp.execute(ge
Now I am looking at the easiest way to get this accomplished in vb without using the ADODC objects.. hopefully something similar to the way I do it above.. If you know of a better way I should be doing this other than odbc adn recordsets, I am open to suggestions..
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the solution. I was on the right track, just got a little confused on the syntax..
Dim sCon as string
Dim rsUser as New ADODB.Recrodset
Dim cnUser as New ADODB.Connection
sCon = "Provider=Microsoft.Jet.OL
"Data Source=C:\my documents\mb.mdb;"
cnUser.Open scon
sSql = "Select * From t_user"
rsUser.Open ssql,cnUser,2,1
Ok this opens connection to your database and the creates a recordset based on your table User. for example now you want to populate listbox with some data from Field User in your database. You do this like this.
Do while not rsUser.Eof
List1.additem rsUser("user")
loop
this will populate the listox with all the users taken from Field User in your table.
Ok the way you open your recordset is fine. The only problem with it is it READ-Only now. When you execute the connection object to create a recordset it will be read-only.
Now the other persons example will aslo create a read only recordset since he didn't specify what type of recordset he opened.
rstemp.Open GetData,conntemp
'Then do your stuff
Well i hope this helps a bit.