Link to home
Start Free TrialLog in
Avatar of tchous
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.createobject("adodb.connection")

conntemp.open myDSN
set rstemp=conntemp.execute(getdata)

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
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Marine
Marine

Here is the example where i am using OLEDB Drivers instead of ODBC DSN.whe you mean ADODC object you spcefically mentioning about its data control. Its good if you want to deal with bound data controls. It can be time saving but its limited to certain things like flexibility of use. OK My example uses OLEDB drivers and ADO objects in code.

Dim sCon as string
Dim rsUser as New ADODB.Recrodset
Dim cnUser as New ADODB.Connection

sCon = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"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.
Avatar of tchous

ASKER

Thanks for the solution. I was on the right track, just got a little confused on the syntax..