简体   繁体   中英

Need to copy an entire table from SQL Server to SQL Server CE including the table structure and all data

I'm looking to copy tables including all their data from SQL Server to a SQL CE database in C# on demand. The trick is, the tables being copied will not be known until runtime and will not previously exist in the SQL CE database.

I'm hoping to do this by getting a DataTable from the server first and then copying that into the CE database.

What is the simplest way to insert that new table and its data to the SQL Server CE database?

And is there an alternative method I should consider?

The method would have to work on any version of SQL Server from 2005 and up so I cannot rely on a feature only available in newer versions.

The local DB will always be blank.

The tables may contain up to several thousand records and this is going to be used as a local cache.

Thanks in advance

What I've done so far and tested on a sample project is:

  • Get the data into a DataTable from SQL Server
  • Create a create table script using the DataTable 's column collection
  • Run that against my SQL Server CE database

And found a library written by someone else to do a bulk copy into the CE database since the regular SQL bulk copy does not support CE.

I need to integrate it into the main app and test it against real production data to see how it performs, but provided that is acceptable I'm going this route I think.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM