开发者

Generate script Insert in .net

开发者 https://www.devze.com 2023-01-20 05:42 出处:网络
I have problem when trying generate script insert with specific condition. So far I am already trying this step.

I have problem when trying generate script insert with specific condition.

So far I am already trying this step.

  1. Add references Microsoft.SqlServer.ConnectionInfo and Microsoft.SqlServer.Smo

  2. Add reference in code Microsoft.SqlServer.Management.Smo

  3. Add this to s开发者_Go百科cript.

      var srv = new Server(@"localhost\SQLEXPRESS");
      var db = srv.Databases["Northwind"];
      foreach (Microsoft.SqlServer.Management.Smo.Table tab in db.Tables)
      {
          foreach (string s in tab.Script())
          {
              File.AppendAllText("sql_insert_conditioanl.sql", s);
          }
      }
    

Script "sql_insert_conditioanl.sql" contain only to create database and create table that exist in database "Northwind".

So I do research about this problem. Trying change method "Script" without parameter to parameter "ScriptingOptions" ref link. I still confuse to using parameter Scripting Options.

Then also trying using protected method. But since it protected, I can't test method (like: Method "ScriptAlter").

Regard


You need to generate scripts for all database objects - for example indices, stored procedures, views etc. See this article (and its related articles) for getting started.

0

精彩评论

暂无评论...
验证码 换一张
取 消