Solved

tutorial on how to connect Access Database using VB6

Posted on 2010-09-11
7
357 Views
Last Modified: 2013-12-25
How to connect Access Database 2003 using VB6 without ADO Data Control.
How to Add, edit, delete, retreive.
0
Comment
Question by:PagodNaUtak
  • 4
  • 2
7 Comments
 
LVL 4

Accepted Solution

by:
antonybrahin earned 500 total points
ID: 33655728

'in general section
dim conn as adodb.connection
dim rs as adodb.recordset

'in form load
set conn=new adodb.connection
set rs=new adodb.recordset

conn="provider=microsoft jet.4.0.oledb;data source=<ur database name>;persist security info=false"
conn.open
rs.open "select *from ur tablename",conn,adopendynamic,adlockoptimistic

Open in new window

0
 
LVL 65

Expert Comment

by:rockiroads
ID: 33655732
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
0
 
LVL 4

Expert Comment

by:antonybrahin
ID: 33655736
sorry abt the previous post..

refer this for ADO DC.

http://www.vb6.us/tutorials/database-access-ado-vb6-tutorial
0
ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

 
LVL 6

Expert Comment

by:judgeking
ID: 33655738
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:
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 33655739
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

0
 
LVL 65

Expert Comment

by:rockiroads
ID: 33655743
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.
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 33776228
Just curious why you accepted ADO when you said you didn't want ADO control. Its not about points but rather your question.
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question