Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 123»»»

SSIS capturing multiple variables Expand / Collapse
Author
Message
Posted Thursday, August 14, 2014 9:20 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, September 10, 2014 7:43 AM
Points: 12, Visits: 35
Hello, I would be grateful if anyone could help me. I have to modify an SSIS package that someone else has written that prompts the user for a variable using the code below. All I want to do is for the form that pops up to have 20 fields, so when the button is clicked it assigns the value put in the second field to a second variable (Campcode2), the value in the third field to a third variable (Campcode3) etc etc...then I guess the void inputset_Click would contain:

Dts.Variables["CampCode"].Value = txt.Text.ToString();
Dts.Variables["CampCode2"].Value = txt.Text.ToString();
Dts.Variables["CampCode3"].Value = txt.Text.ToString();

If anyone can think of a simple way of doing this I would really appreciate it. Many thanks. I do not understand C#, I don't know what I have to put in the form code to create 19 new fields and then assign them to 19 new variables

using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;

namespace ST_21bd9709f1944de2a5f7eaf9faac94cd.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


System.Windows.Forms.Form frm = new Form();
TextBox txt = new TextBox();
Button inputset = new Button();
public void Main()
{
inputset.Text = "Enter Campaign Code";
inputset.Width = 100;
inputset.Height = 200;
inputset.Click += new EventHandler(inputset_Click);
txt.Name = "Input";
frm.Controls.Add(txt);
frm.Controls.Add(inputset);
frm.ShowDialog();


Dts.TaskResult = (int)ScriptResults.Success;
}

void inputset_Click(object sender, EventArgs e)
{
Dts.Variables["CampCode"].Value = txt.Text.ToString();
frm.Close();
}
}
}
Post #1603343
Posted Thursday, August 14, 2014 11:21 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 6:25 PM
Points: 6,256, Visits: 7,436
john.brees (8/14/2014)
Hello, I would be grateful if anyone could help me. I have to modify an SSIS package that someone else has written that prompts the user for a variable using the code below.

Wait, whut? This is quite possibly the worst use of SSIS you can do. SSIS is meant for automation behind the scenes and was never intended for user interfacing. This is why you're running into such significant problems trying to do it. It'll fight you every step of the way.

Yes, like everything else it can be done. You're opening up a can of worms you don't realize yet though if you try.

Are you willing to back this discussion up a bit? What is the purpose of this SSIS package and user interface? Maybe we can give you something a lot more friendly to attempt to implement.



- Craig Farrell

Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

For better assistance in answering your questions | Forum Netiquette
For index/tuning help, follow these directions. |Tally Tables

Twitter: @AnyWayDBA
Post #1603397
Posted Thursday, August 14, 2014 11:38 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Today @ 2:54 PM
Points: 216, Visits: 573
Any specific reason for having the UI. why don't you just put all the 20 variables in a confiuration file and pass those values at the runtime?
Post #1603412
Posted Friday, August 15, 2014 2:18 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, September 10, 2014 7:43 AM
Points: 12, Visits: 35
Thanks for the replies. It's running a sql stored procedure that has one argument. It's working well for the one argument, I just need to know how to modify the windows form. A configuration file is not going to be suitable, it's been in use for some time by an end user. I want to expand it to 20 variables, I just want it to store whatever is entered, if anything is entered.

I would really appreciate it if a visual C# expert could tell me how to modify the windows form to take 20 strings, then how to convert the strings to 20 variables. I know it is not ideal.

Many thanks
Post #1603598
Posted Friday, August 15, 2014 2:26 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, September 10, 2014 7:43 AM
Points: 12, Visits: 35
It is pulling customers out of a database according to the codes that are entered, the codes come over in a brief, there may be 1 or more than 1 but 20 should be sufficient
Post #1603602
Posted Friday, August 15, 2014 10:17 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Today @ 2:54 PM
Points: 216, Visits: 573

You also need to declare 20 variables named dtsCampaign_Code1,dtsCampaign_Code2 .....dtsCampaign_Code20 in the Variables window.


System.Windows.Forms.Form frm = new Form();
Label[] lblCampaignCode = new Label[20];
TextBox[] txtCampaignCode = new TextBox[20];
Button btnCampaignCode = new Button();
// Create a variables 'container' to store variables
Variables vars = null;


public void Main()
{

for (int i = 0; i < lblCampaignCode.Length; i++)
{

var lblCampaign_Code = new Label();
lblCampaignCode[i] = lblCampaign_Code;
lblCampaign_Code.Name = "lblCampaign_Code" + (i+1);
lblCampaign_Code.Text = "CampaignCode" + i+1;
lblCampaign_Code.Location = new Point(15, 32 + (i * 28));
lblCampaign_Code.Visible = true;
lblCampaign_Code.Font = new Font(lblCampaign_Code.Font, FontStyle.Bold);
lblCampaign_Code.TextAlign = ContentAlignment.MiddleCenter;
lblCampaign_Code.AutoSize = true;
frm.Controls.Add(lblCampaign_Code);
}




for (int i = 0; i < txtCampaignCode.Length; i++)
{

var txtCampaign_Code = new TextBox();
txtCampaignCode[i] = txtCampaign_Code;
txtCampaign_Code.Name = "txtCampaign_Code" + (i+1);
txtCampaign_Code.Location = new Point(172, 32 + (i * 28));
txtCampaign_Code.Visible = true;
txtCampaign_Code.Font = new Font(txtCampaign_Code.Font, FontStyle.Bold);
//txtCampaign_Code.TextAlign = ContentAlignment.MiddleCenter;
txtCampaign_Code.AutoSize = true;
frm.Controls.Add(txtCampaign_Code);
}

btnCampaignCode.Name = "btnCampaignCode";
btnCampaignCode.Text = "Submit";
btnCampaignCode.Visible = true;
btnCampaignCode.Font = new Font(btnCampaignCode.Font, FontStyle.Bold);
btnCampaignCode.AutoSize = true;
btnCampaignCode.Location = new Point(125, 32 + (23 * 28));
frm.Controls.Add(btnCampaignCode);
btnCampaignCode.Click += new EventHandler(btnCampaignCode_Click);





frm.WindowState = FormWindowState.Maximized;
frm.ShowDialog();


Dts.TaskResult = (int)ScriptResults.Success;
}

void btnCampaignCode_Click(object sender, EventArgs e)
{


foreach (TextBox inputBox in txtCampaignCode)
{

string variable = "dts" + inputBox.Name.Replace("txt", "");
// Lock variables
Dts.VariableDispenser.LockForWrite(variable);
// Add variables from the VariableDispenser to the variables 'container'
Dts.VariableDispenser.GetVariables(ref vars);

// Now you can use the variables
if (inputBox.Name.ToString().Substring(3, (inputBox.Name.ToString().Length) - 3) == variable.ToString().Substring(3, (variable.ToString().Length) - 3))
{

int number;
if( (int.TryParse(inputBox.Text, out number)) == true)
{
vars[variable].Value = Convert.ToInt32(inputBox.Text);
}
// if DTS varibale is of type String

// vars[variable].Value = inputBox.Text.ToString();

}
// Release the locks
vars.Unlock();

frm.Close();

}


}
}


Post #1603772
Posted Friday, August 15, 2014 2:24 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, September 10, 2014 7:43 AM
Points: 12, Visits: 35
rxm119528 thank you so much! I do appreciate your help, you are a great guy thanks again

Post #1603876
Posted Wednesday, September 3, 2014 4:11 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, September 10, 2014 7:43 AM
Points: 12, Visits: 35
Thanks very much for this, I have tried using and it is only giving a couple of errors, the line:

Variables vars = null;

gives error:

Error 1 The type or namespace name 'Variables' could not be found (are you missing a using directive or an assembly reference?)

and:

Dts.VariableDispenser.GetVariables(ref vars);

gives error:

Error 2 The best overloaded method match for 'Microsoft.SqlServer.Dts.Runtime.VariableDispenser.GetVariables(ref Microsoft.SqlServer.Dts.Runtime.Variables)' has some invalid arguments st_c8fd8765cc1c4f55ba93d8a2aadcd90f
Error 3 Argument '1': cannot convert from 'ref Variables' to 'ref Microsoft.SqlServer.Dts.Runtime.Variables'

I have created the 20 variables in SSIS, dtsCampaign_Code1, dtsCampaign_Code2, dtsCampaign_Code3.....dtsCampaign_Code20 as string variables.

If anyone could help I would really appreciate it, I can see this is so close to working now!!

Many thanks

Post #1609935
Posted Wednesday, September 3, 2014 7:08 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Today @ 2:54 PM
Points: 216, Visits: 573
using Microsoft.SqlServer.Dts.Runtime

should be there in the namespace list.
Post #1610007
Posted Wednesday, September 3, 2014 7:24 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, September 10, 2014 7:43 AM
Points: 12, Visits: 35
Oh great thank you, that has removed those errors. The only errors I am getting now are whenever these 3 lines appear:

lblCampaign_Code.Location = new Point(15, 32 + (i * 28));
lblCampaign_Code.Font = new Font(lblCampaign_Code.Font, FontStyle.Bold);
lblCampaign_Code.TextAlign = ContentAlignment.MiddleCenter;

I get
Error 1 The type or namespace name 'Point' could not be found (are you missing a using directive or an assembly reference?)
Error 2 The type or namespace name 'Font' could not be found (are you missing a using directive or an assembly reference?)
Error 3 The name 'FontStyle' does not exist in the current context
Error 4 The name 'ContentAlignment' does not exist in the current context

Am I missing another reference?

thanks so much for help so far
Post #1610019
« Prev Topic | Next Topic »

Add to briefcase 123»»»

Permissions Expand / Collapse