Question:

How to connect the table in MS access to visual basic and what are code behind?

by  |  earlier

0 LIKES UnLike

How to connect the table in MS access to visual basic and what are code behind?

 Tags:

   Report

2 ANSWERS


  1. Follow these URLs. These lessons deals with connecting with database in visual basic

    http://visualbasic.freetutes.com/learn-v...

    http://visualbasic.freetutes.com/learn-v...

    http://visualbasic.freetutes.com/learn-v...


  2. To connect vb6.0 and MS access, I will make an example of connecting them using ADO DB.

    Dim sConn as string 'for the connection string

    'now we declare the ADO DB connection

    'to be able to show this NEW ADO DB.Connection line, you must do the following:

    1. in the toolbox, you must add a component.

    2. in the component box, find the Microsoft ActiveX ADO connection something like that.

    3. then when this is done, drag the component into your form and then delete it

    4. this way you may be able to have the NEW ADO DB line in your intelligence

    now lets proceed to connecting you db and vb6.0

    Dim db as New ADO DB.Connection

    dim rs as new ADO DB.Record-set

    dim sPath as string ' here we put the path of your database

    dim sSQL as string 'your SQL Statement

    'like for example your vb application is on C:\MyVB

    ' and within that your DB is under another folder called DB

    ' we must get the path C:\MyVB\DB\yourdbname.mdb

    ' we shall be using app.path for getting the path of your application that is the C:\MyVB

    ' then we must concatenate the folder and the name of your database.

    sPath = app.path & "\DB\yourdbname.mdb;"

    'initialize the connection string

    sConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sPath

    sSQL = "SELECT * FROM yourtablename"

    now let us proceed to the main part

    Private Sub frmMain_Load()

    db.ConnectionString = sConn

    db.Open

    with rs

    .activeconnection = db

    .locktype = adlockoptimistic

    .cursortype = adopenkeyset

    .open sSQL

    ' now let us loop through your records and show it to your label

    ' for example your table has two fields, the field called name and description

    do while not .eof

    label1.caption = .fields("name").value & vbCrLf & .fields("description").value & vbCrLf

    .movenext

    loop

    'let close the rs connection

    rs.close

    end with

    set rs = nothing

    db.close

    set db = nothing

    End Sub

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.