Using SMO to script PARTIAL data content (only rows matching a WHERE clause)

≡放荡痞女 提交于 2019-12-23 02:18:56

问题


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 ?


回答1:


Doesn't look like SMO supports WHERE clause or any other mechanism to limit the number of records. My suggested workaround is to create a new table containing the subset of records, script it, then drop it. Everything can be done programmatically.



来源:https://stackoverflow.com/questions/35358122/using-smo-to-script-partial-data-content-only-rows-matching-a-where-clause

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!