Link to home
Start Free TrialLog in
Avatar of Bob Valentine
Bob ValentineFlag for United States of America

asked on

VB.Net Code to copy a table from one database to another one located in a different folder

I need to copy a table from the main Access database and insert it into another database that is located in a different folder. I am programming in VB.Net. Below is the code I am trying. It gives me an error message at the "cmd.ExecuteNonQuery()" statement.

The error says:  {"Query input must contain at least one table or query."}. I have a database at the external folder location called AssetDatabase.accdb into which I want the table copied. What am I doing in correctly? Is the syntax wrong?

cmd = New OleDbCommand("Select * INTO  [tblAssetData-" & CompanyName & "] IN C:\Users\rkvjr\Documents\Backup\AssetDatabase.accdb FROM tblAssetData", objcon.con)
cmd.ExecuteNonQuery()
 

Open in new window

Avatar of HainKurt
HainKurt
Flag of Canada image

when you say "copy", you mean you want to copy rows or create the table and copy the data?
Avatar of Bob Valentine

ASKER

I mean create a table and copy the data. The new table will be in a different folder location than the original.
what is exact error message?
The error says:  {"Query input must contain at least one table or query."}.

Is the syntax of the following statement correct? Is that what is causing the error?

cmd = New OleDbCommand("Select * INTO  [tblAssetData-" & CompanyName & "] IN C:\Users\rkvjr\Documents\Backup\AssetDatabase.accdb FROM tblAssetData", objcon.con)

Open in new window

SELECT…INTO Statement (Microsoft Access SQL)

https://msdn.microsoft.com/en-us/library/bb208934(v=office.12).aspx

your query looks ok...

what happens when you run this from access db?
ASKER CERTIFIED SOLUTION
Avatar of Bob Valentine
Bob Valentine
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
By experimentation I found that the code executed properly when the IN path was enclosed in quotation marks.