Importing external modules

The search path for importing C# modules can be extended in the script itself, for example:


Example:

#r "C:\\Program Files\\Microsoft SQL Server\\120\\SDK\\Assemblies\\Microsoft.SqlServer.Smo.dll"
#r "C:\\Program Files\\Microsoft SQL Server\\120\\SDK\\Assemblies\\Microsoft.SqlServer.ConnectionInfo.dll"

using System;
using Microsoft.SqlServer.Management.Smo;

Importing and using ScriptoMate Types

Example:

//ScriptoMate types

//VSApi is already loaded in ScriptoMate by default, only one using statement required

using VSApi;


//Other types

#r "System.Windows.Forms"
using winforms = System.Windows.Forms;

Accessing Host objects 

Please refer to the Scripting Host Object Model

Most common uses

//Set property
ScriptData.Variables["myDouble"].Value += 1.0;

//Get property
double myDouble = (double) ScriptData.Variables[varName].Value;


//Call a sub routine

ScriptData.Variables.Remove("Test");


//Call a function

string err = IsRuntimeError().ToString();


//Create object

string varName = "new_var";
VSVariable var = new VSVariable(varName, VSVariableDataType.String, varName + " (set by C# script)", varName + " (set by C# script)", false, VSVariableDefinitionType.VSDynamic);
ScriptData.set_Variable(varName, var);


//Datatable.RepeatScript

//DR_TRX is the Datarow set by the repeater

DataRow dr = (DataRow) ScriptData.Variables["DR_TRX"].Value;
long amount = dr.Field<long>("AMT_OR_QTY");
dr["AMT_OR_QTY"] = amount  * 100;


Misc.RunScript examples

Host Object

Example file

Host.ScriptData.Variables

Xml\Tutorial\5001 Advanced topics\0401 Creating scripts\CSharp.Variables.xml

Host.ScriptData.MailServers

Xml\Tutorial\5001 Advanced topics\0401 Creating scripts\CSharp.MailServers.xml

Host.ScriptData.FtpServers

Xml\Tutorial\5001 Advanced topics\0401 Creating scripts\CSharp.FtpServers.xml

Host.Progress

Xml\Tutorial\5001 Advanced topics\0401 Creating scripts\CSharp.Progress.xml

Host.DatasetManager

Planned

Host.AppManager

Xml\Tutorial\5001 Advanced topics\0401 Creating scripts\CSharp.Application.xml

Datatable.RepeatScript examples

Host Object

Example file

Host.ScriptData.Variables

Xml\Tutorial\5001 Advanced topics\0401 Creating scripts\Datatable.RepeatScript.CSharp.xml