You could use my scripting library, which can script entire schema to a file, and run the script using the ExecuteSql method against the other sdf file.
http://exportsqlce.codeplex.com
var a = Database.Open("a");
var data = a.Query("SELECT * FROM Table1");
var b = DatabaseOpen("b");
//if the table already exists
foreach(var row in data){
b.Execute("INSERT INTO Table1 (col1,col2,col3,...) VALUES (@0, @1, @2...)", row.col1, row.col2,row.col3,...);
}
If the table doesn't exist, you need to create it. You can use CREATE TABLE for that:
var ddl = "CREATE TABLE Table1 (Col1 IDENTITY NOT NULL PRIMARY KEY, Col2 NVARCHAR(50), Col3 DATETIME etc)";
b.Execute(ddl);
Member
15 Points
13 Posts
How to copy a table from another database?
Aug 24, 2013 03:17 AM|webMvc|LINK
table 1in a.sdf
how can I copy table1 to b.sdf
Participant
1499 Points
501 Posts
Re: How to copy a table from another database?
Aug 24, 2013 03:23 AM|atulthummar|LINK
Hello,
You could use my scripting library, which can script entire schema to a file, and run the script using the ExecuteSql method against the other sdf file. http://exportsqlce.codeplex.com
http://social.msdn.microsoft.com/Forums/sqlserver/en-US/4b2ec5ac-6e28-49b3-ac38-5b622cd50bb3/copy-table-from-sdf-to-sdf-database
Atul T.
Please click "mark as answer" if this post helped you.
All-Star
194018 Points
28030 Posts
Moderator
Re: How to copy a table from another database?
Aug 24, 2013 03:32 AM|Mikesdotnetting|LINK
If the table doesn't exist, you need to create it. You can use CREATE TABLE for that: