Results 1 to 10 of 10

Thread: A Simple ADO Example

  1. #1

    Thread Starter
    Hyperactive Member venkatraman_r's Avatar
    Join Date
    Jul 1999
    Location
    Chennai, INDIA
    Posts
    284

    Post

    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.

  2. #2
    Addicted Member
    Join Date
    Jun 1999
    Location
    Los Angeles
    Posts
    186

    Post

    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é

  3. #3
    New Member
    Join Date
    Dec 1999
    Location
    India
    Posts
    9

    Post

    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.

  4. #4

    Thread Starter
    Hyperactive Member venkatraman_r's Avatar
    Join Date
    Jul 1999
    Location
    Chennai, INDIA
    Posts
    284

    Post

    But, its the simpler way to learn ado instead of going for complex codes. pls..help me with some examples.

    thanx.

    regards,

    venkat.

  5. #5
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844

    Post

    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.

  6. #6
    Hyperactive Member
    Join Date
    Jun 1999
    Posts
    308

    Post

    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

  7. #7
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    Here is a small example with comments. Requires Listbox (List1) and Command Button (Command1):
    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
    In this example I'm using Northwind database and a table called Employees.

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

    Serge

    Software Developer
    [email protected]
    ICQ#: 51055819


  8. #8

    Thread Starter
    Hyperactive Member venkatraman_r's Avatar
    Join Date
    Jul 1999
    Location
    Chennai, INDIA
    Posts
    284

    Post

    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.

  9. #9
    Member
    Join Date
    Dec 1999
    Posts
    37

    Post

    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).]

  10. #10

    Thread Starter
    Hyperactive Member venkatraman_r's Avatar
    Join Date
    Jul 1999
    Location
    Chennai, INDIA
    Posts
    284

    Post

    Hi Ruchi,

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

    Regards and a very happy millenium.

    Bye,

    Venkat.

    ------------------
    [email protected]
    ICQ: 45714766

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width