Access Database Connection,

Dear Friends,

I am very much familir in VB 6.0 but I need to develop a similar project in VB 2005.

I use the following code and variables for my database caonnection.

Public db, db1 As Database
Public rs, rsFDEprod, rsFDEtime, rsOPSprod, rsOPStime, rsANAprod, rsANAtime, rsQA As Recordset

Public Function connect()
Set db = OpenDatabase("C:\Documents and Settings\bedwin\My Documents\EX1.mdb")
Set rs = db.OpenRecordset("select * from LOGIN", dbOpenDynaset)
End Function

I would like to know the code i need to use in VB 2005..

I should a search a record set with a form entry...and also add record to the database in Access

I really need your help very urgently.

Thanks,

Bjor




Answer this question

Access Database Connection,

  • Terry B

    And to update, insert, or delete, you can use something like this...

    Dim cn As New OleDbConnection("Data Source=C:\Documents and Settings\bedwin\My Documents\EX1.mdb;Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;")
    Dim cmd As New OleDbCommand("update LOGIN set LastAccessDate = #' & Now & '#", cn)

    Dim rowsAffected As Integer

    rowsAffected = cmd.ExecuteNonQuery()

    cn.Close

     


  • itisapple

    Bjorn, try something like this...

    Dim cn As New OleDbConnection("Data Source=C:\Documents and Settings\bedwin\My Documents\EX1.mdb;Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;")
    Dim cmd As New OleDbCommand("select * from LOGIN", cn)
    Dim dr As OleDbDataReader

    cn.Open()
    dr = cmd.ExecuteReader

    If Not dr.HasRows Then
    MsgBox("No Records Found.")
    Exit Sub
    End If

    Do While dr.Read()
    MsgBox(dr("UserID"))
    Loop

    dr.Close
    cn.Close


  • Access Database Connection,