Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

tutorial on how to connect Access Database using VB6

Posted on 2010-09-11
7
Medium Priority
?
380 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 4

Accepted Solution

by:
antonybrahin earned 2000 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

636 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