PDA

Click to See Complete Forum and Search --> : A Simple ADO Example


venkatraman_r
Dec 29th, 1999, 11:31 AM
Hi All,

Can anyone gimme a simple example of using a ADO with comments. I am trying to connect to access database and retrieve the values from a table.

I am totally new to ADO. Please help.

Regards,

Venkat.

André
Dec 29th, 1999, 01:22 PM
Hi there, the best you can do is take a look at th tuorial here on this site on using VB with databases, click on Databases, and you will find good tutorials.

happy Y2K

André

suthin
Dec 29th, 1999, 05:03 PM
If you are going to connect to Access databases, its bette to continue with DAO instead of ADO, as it uses the JET database engine to connect to the native backend ie Access.

venkatraman_r
Dec 29th, 1999, 05:42 PM
But, its the simpler way to learn ado instead of going for complex codes. pls..help me with some examples.

thanx.

regards,

venkat.

Clunietp
Dec 29th, 1999, 09:26 PM
I have posted a relatively simple one here http://www.vb-world.net/ubb/Forum3/HTML/002333.html

BTW, ado still uses the MS Jet database engine, just via OLEDB, not DAO, and DAO will be fading away (if it hasn't already) so if you learn anything, learn ADO.

LG
Dec 29th, 1999, 10:49 PM
Hi,there. Happy New Year!
Check Microsoft side, there is a lot of examples how to use ADO. http://msdn.microsoft.com/library/psdk/dasdk/mdae82eb.htm
Good luck!
Larisa

Serge
Dec 30th, 1999, 11:02 AM
Here is a small example with comments. Requires Listbox (List1) and Command Button (Command1):

Private Sub Command1_Click()
Dim cn As New ADODB.Connection 'Connection object
Dim rs As New ADODB.Recordset 'Recordset object
Dim strDBPath As String

strDBPath = "C:\Program Files\Microsoft Visual Studio\VB98\Nwind.mdb"
'Set the native OLEDB provider for Jet (Access database)
cn.Provider = "Microsoft.Jet.OLEDB.3.51"
'Open connection for Northwind database, where the UserID is Admin and no password
cn.Open strDBPath, "admin", ""
'Open recordset for the Employees table
rs.Open "Select * from Employees", cn, adOpenStatic
'Populate the Listbox with last and first names
Do Until rs.EOF
List1.AddItem rs(1) & ", " & rs(2)
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub


In this example I'm using Northwind database and a table called Employees.

------------------

Serge

Software Developer
Access8484@aol.com
ICQ#: 51055819 (http://www.icq.com/51055819)

venkatraman_r
Dec 30th, 1999, 11:20 AM
Hi Serge, I know you would come for helping me. Thanks and a big salute to you.

Well, this is the code i tried of my own. But it didnt work. Can u tell me where I had made the mistake?

-----
Dim CN As New ADODB.Connection
Dim rs As ADODB.Recordset

'Opening the connection to the pubs database
CN.Open "databse=database=d:\personal\payroll.mdb;Driver=Microsoft.Jet.OLEDB.3.51;"

'fixing the employee table as recordset
Set rs = CN.Execute("select * from empmast")
rs.MoveFirst
Do Until rs.EOF
MsgBox rs.Fields(0)
rs.MoveNext
Loop
--------

And where do i get the list of drivers to be used in ADO?

Thanx again and Regards,

Venkat. :) :)

Ruchi
Dec 30th, 1999, 12:02 PM
Change


CN.Open "databse=database=d:\personal\payroll.mdb;Driver=Microsoft.Jet.OLEDB.3.51;"


to


CN.Open "Data Source=d:\personal\payroll.mdb;Provider=Microsoft.Jet.OLEDB.3.51"


This should work.

Ruchi

[This message has been edited by Ruchi (edited 12-31-1999).]

venkatraman_r
Dec 30th, 1999, 12:29 PM
Hi Ruchi,

That was a perfect shot..It worked well..Thanx ya.

Regards and a very happy millenium.

Bye,

Venkat. :) :)

------------------
venkatraman_r@email.com
ICQ: 45714766