Access to Sql table bulk copy

Hi:
In VB I have the user select the Access database, and SQL database dynamically. In other parts in VB, I have created a table in both Access and SQL using the command object. Now, I need to get the data from SQL table to Access table. Notice these are the tables I have created in VB so they have the same sturcture.  I need the most efficient code example to bulkcopy the table from SQL to Access. NOT ROW BY ROW. Please help me with this. I am using VB6 and SQL 2000.
dhamijapAsked:
Who is Participating?
 
aikimarkConnect With a Mentor Commented:
The VB code to attach the SQL Server table to the MSAccess database should look something like:

Set DAOtabledefobject = DAOdatabaseobject.tabledefs.append "attachedname"

DAOtabledefobject .connectstring = "odbc;driver={SQL Server};server=myserver;database=pubs;uid=myuid;pwd=mypwd"

DAOtabledefobject.RefreshLink

======================
Once the table is attached, you can execute the appending SQL in the MSAccess database to accomoplish the row append.

======================
NOTE: If you submit the SQL with the IN sub-clause (from my initial comment) you don't need to execute the attach code.
0
 
PePiCommented:
i think you should also post this question in http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/
0
 
dhamijapAuthor Commented:
you mean a copy of it. How will I do that I never done that? Could you tell me please.
dhamijap
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
aikimarkCommented:
Try something like:

Insert Into DestAccessTablename
From SQLSvrTablename IN "odbc;driver={SQL Server};server=myserver;database=pubs;uid=myuid;pwd=mypwd"
0
 
aikimarkCommented:
Please note that Microsoft indicates you will get better performance from an attached table than using the IN clause.
0
 
LowfatspreadCommented:
dependant on the amount of data involved....

1 create a linked table in the access database pointing to the SQL Server table

then do

Insert into AccessTable
 (column list)
 Select (column list)
 from linkedSQLServerTable
 order by (column list specifying the order the data should be inserted in)

if large amounts of data will be transfered then
it may be better to export the data from the SQL server database to a file
and then import that into access...  


hth






 
0
 
dhamijapAuthor Commented:
Lowfatspread:
I need the sample code I have never done this!
dhamijap
0
 
aikimarkCommented:
dhamijap,

What kind of "sample code" do you need?
0
 
dhamijapAuthor Commented:
aikimark:
you can assume that i cam make connections of mdb file and sql server but I need rest everything.
dhamijap
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.