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.
Printable View
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.
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é
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.
But, its the simpler way to learn ado instead of going for complex codes. pls..help me with some examples.
thanx.
regards,
venkat.
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.
Hi,there. Happy New Year!
Check Microsoft side, there is a lot of examples how to use ADO. http://msdn.microsoft.com/library/ps...k/mdae82eb.htm
Good luck!
Larisa
Here is a small example with comments. Requires Listbox (List1) and Command Button (Command1):
In this example I'm using Northwind database and a table called Employees.Code: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
------------------
Serge
Software Developer
[email protected]
ICQ#: 51055819
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. :) :)
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).]
Hi Ruchi,
That was a perfect shot..It worked well..Thanx ya.
Regards and a very happy millenium.
Bye,
Venkat. :) :)
------------------
[email protected]
ICQ: 45714766