I need some help because i am trying to do this
use a

Cn as new ADODB.Connection , and a Dao
Rs as Dao.Recordset

so i need to put this to together? because i had a test in my university
and my teacher put this in the exam, and nobody couldnt solve
neither do i, i need to know if is possible to do it
use a adodb connection with a dao recordset, i think is no possible

But, what do you think ?

Note: Nobody pass the exam!

Dani AI

Generated

As and pointed out, you cannot directly use an ADODB.Connection as the connection for a DAO.Recordset. DAO and ADO are separate object models with different Connection/Recordset types; there is no built‑in adapter that lets a DAO recordset accept an ADODB connection object.

Two practical approaches that solve the usual goal (talk to a database and read/write rows):

Use ADO end-to-end (recommended for OLE DB/SQL Server, remote data)

Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset

Set cn = New ADODB.Connection
cn.Open "Provider=SQLOLEDB;Data Source=MyServer;Initial Catalog=MyDB;Integrated Security=SSPI;"
Set rs = New ADODB.Recordset
rs.Open "SELECT * FROM MyTable", cn, adOpenKeyset, adLockOptimistic

Use DAO end-to-end (recommended for Jet/Access local .mdb/.accdb in older VB6 apps)

Dim db As DAO.Database
Dim drs As DAO.Recordset

Set db = DBEngine.Workspaces(0).OpenDatabase("C:\data\MyDb.mdb")
Set drs = db.OpenRecordset("MyTable", dbOpenDynaset)

Notes and exam tip: if both ADO and DAO libraries are referenced in VB6, always fully qualify types (Dim rs As ADODB.Recordset or Dim rs As DAO.Recordset) to avoid ambiguity. If you must move data between models, pull into a Variant array with rs.GetRows (ADO) and then insert into a DAO recordset (or loop the other way). The likely correct exam answer was to state that you cannot mix an ADODB.Connection with a DAO.Recordset directly and to show the correct paired usage or a strategy to transfer data between the two.

Recommended Answers

All 2 Replies

I'm quite positive you cannot do this. You can use an ADO recordset in an ADO connection. It's very similar to using a DAO recordset.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.