frankytee
asked on
using ADO to return records into Access from SQL server
Currently, in MS Access, using DAO/ODBC I "download" data returned from an SQL Server stored procedure into my MS Access front end application. The resulting data drives a user report.
1) I create a pass thru query where the sql is "EXEC spMyprocedure..." etc
2) I then create a make table query which selects from the pass thru query
3) I run the make table query which will then create a table in MS Access containing the resultset of the stored procedure.
The sample DAO code is:
Dim db as database, sConnect as string
Dim qdfSp as querydef, sqlSp as string ‘query which executes the sp
Dim qdfMake as querydef, sqlMake as string ‘query which selects from sp and makes a temp table
Set db = currentdb
sConnect = "....." ‘whatever ODBC connection string
‘now create and define query which calls the sp
sqlSp= "EXEC spMyProcedure " & anyRequiredParameters ‘define string which executes sp
‘either delete and recreate queries or redefine it
Set qdfSp = db.Createquerydef("spQuery ")
with qdfSp
.connect = sConnect ‘it’s a pass thru query
.sql = sqlSp
.ODBCTimeout = 0 ‘no time limit
.ReturnRecords = True
end with
‘now create and define query which makes a table from selecting the sp
sqlMake= "Select .. (fields etc from the resulting output of sp) ... INTO tmpTable FROM " & qdfSp.Name 'select from the pass thru query
Set qdfMake = db.Createquerydef("makeTab leQuery")
with qdfMake
.sql = sqlMake
.ODBCTimeout = 0 ‘no time limit
.ReturnRecords = True
.Execute ‘execute the make table query
end with
set db=nothing
-------------------------- ---------- ---------- ---------- --
Now as MS have been saying the ADO is the future and that DAO is becoming obsolete, I imagine the above must be possible using ADO. However, after experimenting with ADO, I can't get it to create or insert into an Access table that is easily achieved using DAO. The only way possible I can think of is to create an ADO recordset, and then have to loop thru each record and insert individually into an Access table but that would be inefficient when there are thousands of records involved.
Can someone show me the ADO code to do this efficiently without inserting individual records or do I simply stick with DAO?
1) I create a pass thru query where the sql is "EXEC spMyprocedure..." etc
2) I then create a make table query which selects from the pass thru query
3) I run the make table query which will then create a table in MS Access containing the resultset of the stored procedure.
The sample DAO code is:
Dim db as database, sConnect as string
Dim qdfSp as querydef, sqlSp as string ‘query which executes the sp
Dim qdfMake as querydef, sqlMake as string ‘query which selects from sp and makes a temp table
Set db = currentdb
sConnect = "....." ‘whatever ODBC connection string
‘now create and define query which calls the sp
sqlSp= "EXEC spMyProcedure " & anyRequiredParameters ‘define string which executes sp
‘either delete and recreate queries or redefine it
Set qdfSp = db.Createquerydef("spQuery
with qdfSp
.connect = sConnect ‘it’s a pass thru query
.sql = sqlSp
.ODBCTimeout = 0 ‘no time limit
.ReturnRecords = True
end with
‘now create and define query which makes a table from selecting the sp
sqlMake= "Select .. (fields etc from the resulting output of sp) ... INTO tmpTable FROM " & qdfSp.Name 'select from the pass thru query
Set qdfMake = db.Createquerydef("makeTab
with qdfMake
.sql = sqlMake
.ODBCTimeout = 0 ‘no time limit
.ReturnRecords = True
.Execute ‘execute the make table query
end with
set db=nothing
--------------------------
Now as MS have been saying the ADO is the future and that DAO is becoming obsolete, I imagine the above must be possible using ADO. However, after experimenting with ADO, I can't get it to create or insert into an Access table that is easily achieved using DAO. The only way possible I can think of is to create an ADO recordset, and then have to loop thru each record and insert individually into an Access table but that would be inefficient when there are thousands of records involved.
Can someone show me the ADO code to do this efficiently without inserting individual records or do I simply stick with DAO?
ASKER
I should clarify, my workplace only has Access 97 and I only want to use ADO to execute stored procedures (some return resultsets, some return output parameters) in SQL Server.
I still use DAO to manage the data once it gets into Access and ODBC/linked tables so I can bind forms etc at design time.
I still use DAO to manage the data once it gets into Access and ODBC/linked tables so I can bind forms etc at design time.
Hi,
With Access 97 I'd stick to DAO - it is native to Access and simplifies coding etc.
At one stage MS was telling everyone to use DAO. Then they said to use ADO. Now they are saying use ADO.Net.
I'd stick with what is appropriate for your development system - in this case Access 97.
Of course a new project should be in Access XP as a Acess Data Project using ado, or in VB.Net and using ADO.Net.
HTH
Regards
David
With Access 97 I'd stick to DAO - it is native to Access and simplifies coding etc.
At one stage MS was telling everyone to use DAO. Then they said to use ADO. Now they are saying use ADO.Net.
I'd stick with what is appropriate for your development system - in this case Access 97.
Of course a new project should be in Access XP as a Acess Data Project using ado, or in VB.Net and using ADO.Net.
HTH
Regards
David
frankytee
I've developed a few systems that have Access97 front ends with SQL server 6.5 and 2000 backends. The problem with Access97 is that ADO isn't inherently supported, which means you can't make an ADO recordset the recordsource of an Access form or report. What I always ended up doing was using a combination of the two:
I use DAO to
Create pass-thru query's looking at SQL stored procedures or views which I then use as a recordsource for my table or query
I use ADO to
Work with an unbound form. Using ADO I retrieve one record at a time and use these details to fill the controls on the forms. Navigation buttons will start code to get ADO to retrieve the First/Next/Last/Previoes record from SQL server. If you want any help with the code to do this, let me know.
One tip - Access97 doesn't work that well with attached SQL 6.5 tables. It does work but has a tendency to crash the client PC.
Branch40
I've developed a few systems that have Access97 front ends with SQL server 6.5 and 2000 backends. The problem with Access97 is that ADO isn't inherently supported, which means you can't make an ADO recordset the recordsource of an Access form or report. What I always ended up doing was using a combination of the two:
I use DAO to
Create pass-thru query's looking at SQL stored procedures or views which I then use as a recordsource for my table or query
I use ADO to
Work with an unbound form. Using ADO I retrieve one record at a time and use these details to fill the controls on the forms. Navigation buttons will start code to get ADO to retrieve the First/Next/Last/Previoes record from SQL server. If you want any help with the code to do this, let me know.
One tip - Access97 doesn't work that well with attached SQL 6.5 tables. It does work but has a tendency to crash the client PC.
Branch40
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
frankytee:
This old question needs to be finalized -- accept an answer, split points, or get a refund. For information on your options, please click here-> http:/help/closing.jsp#1
EXPERTS:
Post your closing recommendations! No comment means you don't care.
This old question needs to be finalized -- accept an answer, split points, or get a refund. For information on your options, please click here-> http:/help/closing.jsp#1
EXPERTS:
Post your closing recommendations! No comment means you don't care.
use ADO with Access Project ( i.e. Access based on SQL-Server )