Last post May 05, 2013 10:25 AM by CriticalError
May 05, 2013 07:26 AM|CriticalError|LINK
As the title says, how can I copy data from one table in one database to another table in another datbase using SQL Server CE 4.0 ?
May 05, 2013 07:57 AM|CriticalError|LINK
May 05, 2013 09:00 AM|wavemaster|LINK
Care you share your answer?
May 05, 2013 10:25 AM|CriticalError|LINK
Sure basically I opened both databses up and then made a variable which was set to a SQL command which selects all columns from the table you want to copy the data from.
Then I made another SQL Command to insert the data. Used a foreach statement and excuted the SQL Insert command. Here is the code.
var one = Database.Open("dbtocopyto");
var two = Database.Open("copyingfrom");
var pages = two.Query("SELECT * FROM Pages");
var SQLINSERT = @"INSERT INTO tableName (COLUMNS) VALUES (Parameters e.g. @0, @1, @2)";
foreach (var row in pages)
one.Execute(SQLINSERT, /*parmeter objects e.g. row.pName, row.pTitle*/);
Just make sure you create the new table first into the database you wish to copy to, it must have the same columns and same data types and constraints!