Link to home
Start Free TrialLog in
Avatar of PagodNaUtak
PagodNaUtakFlag for Philippines

asked on

tutorial on how to connect Access Database using VB6

How to connect Access Database 2003 using VB6 without ADO Data Control.
How to Add, edit, delete, retreive.
ASKER CERTIFIED SOLUTION
Avatar of antonybrahin
antonybrahin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rockiroads
there is dao. add a reference to microsoft dao library, pick the latest one

to connect to the database, define a dao.database variable and use opendatabase
eg

dim db as dao.database

set db = dao.opendatabase("c:\mydb.mdb")


to close do this

db.close
set db = nothing

to define recordsets you use the db object
eg

dim rs as dao.recordset

set rs= db.openrecordset("select * from mytable")

to close

rs.close
set rs=nothing


the above shows how to select a record, then you iterate using this

dp while rs.eof = false

    'reference your field
    rs!myfield

    'next record
    rs.movenext
loop
Avatar of antonybrahin
antonybrahin

sorry abt the previous post..

refer this for ADO DC.

http://www.vb6.us/tutorials/database-access-ado-vb6-tutorial
Excellent ADO tutorial here:http://www.w3schools.com/ado/default.asp

You don't need to use the ADO Data Control, just the ADO libraries.

Connect is simple:
  Dim  Conn As New ADODB.Connection
  Conn.Provider="Microsoft.Jet.OLEDB.4.0"
  Conn.Open "c:/webdata/northwind.mdb"

Open Recordset/Retrieve:
    Rs.Open "Select * from Customers", Conn, adOpenDynamic, adLockBatchOptimistic
   iCompanyID = Rs.fields("CompanyID")
   Rs.MoveNext
   'etc

Add:
  Rs.AddNew
  Rs.fields("CompanyID") = 1
  Rs.fields("Active") = True
  Rs.UpdateBatch

Delete:
  'Either:
  Conn.Execute "DELETE From Customers WHERE Active=0"
  'Or
  Rs.Find "CustomerID = 99"
  If Not Rs.EOF Then Rs.Delete
 
   

Add:
to add a record you can do it one of two ways

using your recordset

rs.addnew
rs!field1 = somevalue
rs!field2 = somevalue
rs.update

or create a string with your sql and do this

db.execute "sql string"


to delete you can use db.execute

or from the recordset  rs.delete

some more info on dao  http://articles.techrepublic.com.com/5100-10878_11-1045296.html


now you said without using ado, dao is the one thing I can think off. I remember using something called RDO which was oracle's ado equivalent or something but can't think of any other alternatives.
Just curious why you accepted ADO when you said you didn't want ADO control. Its not about points but rather your question.