access connect with vb?

vb6 Greece
  • 13 years ago

    How can I connect db access with vb6?  Read And put in db new records?

     

    nikolas

  • 13 years ago

    1. ado data control ( you can add it in your toolbox n select projetct from th main menu , then click componement) select MICROSOFT  ADO data control
      after placin dat control can connect to a variety of data base types so you have three ways to connect to a db : usin a data link, or ODBC data source, or usin connection string , a data link is a file witk  a udl extension





  • 13 years ago

    any sample code?  or site?

     

    nikolas

  • 13 years ago
    'declare connection and recordset variable
    dim Con as new adodb.connection
    dim Rs as new adodb.recordset

    Inside form_load event...
    dim sql as string

    'open connection
    'cn.Open "provider=Microsoft.jet.oledb.4.0;" & "Data Source=" & App.Path & "\" & ".mdb"

    'open recordset
    sql= "select * from "
    Rs.open sql,cn,1,1

    'start working with data ones you declare and populate recordset
    'be sure to close connection at the end
    set rs = nothing
    cn.close
    set cn=nothing
  • 13 years ago
    'declare connection and recordset variable
    dim Con as new adodb.connection
    dim Rs as new adodb.recordset

    Inside form_load event...
    dim sql as string

    'open connection
    'cn.Open "provider=Microsoft.jet.oledb.4.0;" & "Data Source=" & App.Path & "\" & ".mdb"

    'open recordset
    sql= "select * from "
    Rs.open sql,cn,1,1

    'start working with data ones you declare and populate recordset
    'be sure to close connection at the end
    set rs = nothing
    cn.close
    set cn=nothing
  • 13 years ago

    Hi Nikolas,

    Take the code from "http://www.developerfusion.co.uk/show/207/"

    Regards,

    Aditya

  • 13 years ago
    I prefer that you should put in inside a module or class... anayway create a function inside a module similar to this.

    Option Explicit
    Dim con as new ADODB.Connection
    Dim rs as new ADODB.Recordset
    ---------------------------------------------------------------
    Public Function ConnectDB(sql as String)
    Set con = new ADODB.Connection
    Set rs= new ADODB.Recordset

    con.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Microsoft Visual Studio\VB98\NWIND.MDB;Persist Security Info=False")






    'provide a valid path

    rs.Open sql,con
    rs.close
    set rs = nothing
    set con = nothing
    End Function

    In order for you to use this function call it in your form and provide and SQL statement for the said function.

    Nerd_Pitch
















Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Before software should be reusable, it should be usable.” - Ralph Johnson