I use SMO to fill a SQL Compact database with the data of a SQL server database.
Here is the code I actually use:
foreach(Table l_tblCurrent in l_dbDatabase.Tables)
{
if(l_tblCurrent.IsSystemObject) continue;
ScriptingOptions l_scOptions = new ScriptingOptions();
l_scOptions.NoIdentities = true;
l_scOptions.NoCollation = true;
l_scOptions.NoCommandTerminator = true;
l_scOptions.NoFileGroup = true;
l_scOptions.ScriptSchema = true;
l_scOptions.ScriptData = true;
foreach(string l_strCurrent in l_tblCurrent.EnumScript(l_scOptions))
{
l_sccDBFCommand.CommandText = l_strCurrent.Replace("[dbo].", "");
l_sccDBFCommand.ExecuteNonQuery();
}
}
It works perfectly, but for several tables, I don't want to copy all the rows. I want to be able to select only rows matching a WHERE clause to be copied.
Is it possible ?