How We can pass Result Set from Execute SQL Task into Script Task
1) In Execute SQL Task, create Oledb Connection ,write query in SQLStatement and select Result Set. Create variable with 'Object' data type for passing the Result Set. Add the variable for Result Set.
Create Variable with Object data type
.jpg)
Execute Sql task Properties
Add the object variable for result set in Execute sql task
2) Create Script Task
Pass the Object variable into Script Task
In Script we need to use following name space
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.Data.OleDb;
namespace ST_30eda6583bac466382cfc9fb2148f408.csproj
{
[System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
#region VSTA generated code
enum ScriptResults
{
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
};
#endregion
      
public void Main()
{
string str1;
string str2;
OleDbDataAdapter oledb = new OleDbDataAdapter();
DataTable tb = new DataTable("Emp");
oledb.Fill(tb, Dts.Variables["Result"].Value); //filling the data into table from Result Object
foreach (DataRow rw in tb.Rows )
{
str1 = rw[0].ToString();
str2 = rw[1].ToString();
MessageBox.Show(str1 + " " + str2);
}
Dts.TaskResult = (int)ScriptResults.Success;
}
}
}
1) In Execute SQL Task, create Oledb Connection ,write query in SQLStatement and select Result Set. Create variable with 'Object' data type for passing the Result Set. Add the variable for Result Set.
Create Variable with Object data type
.jpg)
Execute Sql task Properties
2) Create Script Task
Pass the Object variable into Script Task
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.Data.OleDb;
namespace ST_30eda6583bac466382cfc9fb2148f408.csproj
{
[System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
#region VSTA generated code
enum ScriptResults
{
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
};
#endregion
public void Main()
{
string str1;
string str2;
OleDbDataAdapter oledb = new OleDbDataAdapter();
DataTable tb = new DataTable("Emp");
oledb.Fill(tb, Dts.Variables["Result"].Value); //filling the data into table from Result Object
foreach (DataRow rw in tb.Rows )
{
str1 = rw[0].ToString();
str2 = rw[1].ToString();
MessageBox.Show(str1 + " " + str2);
}
Dts.TaskResult = (int)ScriptResults.Success;
}
}
}
.jpg)
.jpg)

No comments:
Post a Comment