Hi all,
I have problem when trying generate script insert with specific condition.
So far I am already trying this step.
Add references Microsoft.SqlServer.ConnectionInfo and Microsoft.SqlServer.Smo
Add reference in code Microsoft.SqlServer.Management.Smo
Add this to script.
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