Solved

tutorial on how to connect Access Database using VB6

Posted on 2010-09-11
7
364 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Updates not working for MS Windows 7 12 181
Add a task in Outlook from access 11 42
Prevent checkbox click event occur while editing it in vb6 8 57
Spell Check in VB6 13 126
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 need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

861 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