Solved

Access to Sql table bulk copy

Posted on 2004-08-23
11
769 Views
Last Modified: 2013-12-25
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.
0
Comment
Question by:dhamijap
11 Comments
 
LVL 6

Expert Comment

by:PePi
ID: 11872517
i think you should also post this question in http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/
0
 

Author Comment

by:dhamijap
ID: 11872599
you mean a copy of it. How will I do that I never done that? Could you tell me please.
dhamijap
0
 
LVL 45

Expert Comment

by:aikimark
ID: 11873087
Try something like:

Insert Into DestAccessTablename
From SQLSvrTablename IN "odbc;driver={SQL Server};server=myserver;database=pubs;uid=myuid;pwd=mypwd"
0
 
LVL 45

Expert Comment

by:aikimark
ID: 11873094
Please note that Microsoft indicates you will get better performance from an attached table than using the IN clause.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 50

Expert Comment

by:Lowfatspread
ID: 11873223
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
 

Author Comment

by:dhamijap
ID: 11880220
Lowfatspread:
I need the sample code I have never done this!
dhamijap
0
 
LVL 45

Expert Comment

by:aikimark
ID: 11884910
dhamijap,

What kind of "sample code" do you need?
0
 

Author Comment

by:dhamijap
ID: 11885351
aikimark:
you can assume that i cam make connections of mdb file and sql server but I need rest everything.
dhamijap
0
 
LVL 45

Accepted Solution

by:
aikimark earned 250 total points
ID: 11886770
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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

896 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now