Jump to content
Xtreme .Net Talk

Recommended Posts

  • *Experts*
Posted

If you want an entire database copied, I'd use the built in tools of the database (Access and SQL Server both have tools to do this - Access is called file copy :))

 

If you really MUST do it in code, you *could* loop through every table and get all rows in a DataSet then use a DataAdapter to do INSERT them all into the second database. That would work if the database were small. For larger databases, you'd probably need a cursor to loop through all the rows in one Database and copy them. This also requires copying tables in the right order, if you have any foreign keys. Also, you'll need custom code per table to keep the foreign keys in sync. OR, turn off identity columns as you do your inserts.

 

If you also need to copy the structure, then... well, you'd better ask :)

 

-nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
  • 1 month later...
Posted

I had the same problem and Robby put me onto this web site that has a lot of useful SQL syntax:

 

Here are few examples . . http://www.w3schools.com/sql/sql_select_into.asp

 

 

The specific syntax that I found that works is:

 

cmd.Connection = ConnectioinName

 

cmd.CommandText = "SELECT * INTO " & {TableName} & " IN '" & (path.database.mdb) & " ' FROM " & {TableName}.

 

On Error GoTo ErrExit

Ival = cmd.ExecuteNonQuery()

If Ival <> 0 Then GoTo errexit

 

This copies a table in open connection to another database.

The SQL samples also give syntax for copying within the same

database.

 

Really slick & it greatly beats the ADOX methods. I am forever indebted to Robby for this scheme.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...