Equivalent ADO

How to Convert my DAO to ADO?
I am using VB6 with MS Access

Dim db as database
Dim rs as recordset

set db = opendatabas("D:\Inventory.mdb")
set rs = db.openrecordset("Item")


with rs
 .addnew
 !itemno = text1.text
 !itemname = text2.text
 .update
end with
ackid32Asked:
Who is Participating?
 
tureConnect With a Mentor Commented:
ackid32,

This should do it:

Sub AdoTest()
  Dim cn As New ADODB.Connection
  Dim rs As New ADODB.Recordset
 
  cn.Provider = "Microsoft.Jet.OLEDB.4.0"
  cn.Open "D:\Inventory.mdb"
  rs.Open "Item", cn, adOpenDynamic, adLockOptimistic
 
  With rs
    .AddNew
    .Fields("itemno").Value = Text1.Text
    .Fields("itemname").Value = Text2.Text
    .Update
  End With
 
  rs.Close
  cn.Close
End Sub

Ture Magnusson
Karlstad, Sweden
0
 
vikiingCommented:
Hey, Ackid32 !!, ¿why don't you pay your older questions first, before going on asking new ones?

Question #10238493 is waiting for your payment since Nov 25th.

0
 
ackid32Author Commented:
but it says "no connection provider" message why?
0
 
vikiingCommented:
you're kidding, ah?
0
 
vikiingCommented:
Clap !!! :)
0
All Courses

From novice to tech pro — start learning today.