Quantcast
Channel: SQL Server Integration Services forum
Viewing all articles
Browse latest Browse all 24688

Mapping Variables to Parameters when building an SSIS package programatically with C#

$
0
0

Hi I I have one final query of the year.  i have much to learn about building SSIS packages with C#.

I have a dataflow task that has a SQL command data source. linked to a Recordset destination.  All works fine.

but now I need to introduce a package variable that gets used in my SQL Command to filter records.  I cant fr the life of my find the correct object within the task t get at the parameters to add them.

My code is like this that creates the task but am struggling to add the parameter. I actually need to add the paramter twices as its used twice in my SQL Command:

            TaskHost mainPipe = e as TaskHost;
            MainPipe dataFlowTask = mainPipe.InnerObject as MainPipe;
            mainPipe.Name = "Get Clients";
           
            IDTSComponentMetaData100 srcComponent = dataFlowTask.ComponentMetaDataCollection.New();
            srcComponent.ComponentClassID = "DTSAdapter.OleDbSource";
            srcComponent.ValidateExternalMetadata = true;

            IDTSDesigntimeComponent100 srcDesignTimeComponent = srcComponent.Instantiate();
            srcDesignTimeComponent.ProvideComponentProperties();

            srcComponent.Name = "Active Clients";
            
            srcDesignTimeComponent.SetComponentProperty("AccessMode", 2);
            srcDesignTimeComponent.SetComponentProperty("SqlCommand", "SELECT [ClientCode] as ClientName, [LinkedServer] FROM [tbl_MCS_Clients] WHERE[RUN] = 1  AND ClientGroup = COALESCE(CASE ? WHEN '' THEN NULL ELSE ? END, ClientGroup)");

            //Where to go next to add the Paramter??
            param.ParameterDirection = ParameterDirections.Input;
            param.ParameterName = "Parameter0";
            param.DtsVariableName = "User::LinkedServer";
            param.ParameterSize = -1;

           // or something like this???
            srcDesignTimeComponent.SetInputProperty(0, "User:ClientGroup");
            srcDesignTimeComponent.SetInputProperty(1,"User:ClientGroup");


Viewing all articles
Browse latest Browse all 24688

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>