C# in SSIS

Hi,

I am coding a "script component" in SSIS by C#.
I try to use  values in a column to be the index of another table (like my code).
but somehow I got error in the run time. I am new to this environment. could someone help me about this issue
this is part of my code, I think error might be in line 18,19

// for Data Set
DataSet objDS1 = new DataSet();
objCmd1.Fill(objDS1, "dis_table1");

int the_Rsize1 = objDS1.Tables["dis_table1"].Rows.Count;
int the_Csize1 = objDS1.Tables["dis_table1"].Columns.Count;

int cur_D_id;
int cur_col3;

// get info from new file
for (int k = 0; k < the_Csize; k++)
{

//** I think problem is in this 2 lines, but I don't know what's wrong about it.
cur_col3 = (int)objDS1.Tables["dis_table1"].Rows[k][1];
cur_D_id = (int)objDS1.Tables["dis_table1"].Rows[k][2];


// insert to output column
for (int i = 2; i < the_Csize; i++) // i==2 from 3rd row
{
MyOutputBuffer.AddRow();
MyOutputBuffer.colvalue = objDS.Tables["tmp_table1"].Rows[i][cur_col3].ToString();
MyOutputBuffer.colvalue = objDS.Tables["tmp_table1"].Rows[i][0].ToString();
MyOutputBuffer.colDid = cur_D_id;
 }
MyOutputBuffer.EndOfRowset();

        }

Open in new window

Snap1.jpg
rmtogetherAsked:
Who is Participating?
 
Carl TawnConnect With a Mentor Systems and Integration DeveloperCommented:
It's because an explicit cast from object to int isn't valid, you need to use int.Parse() instead. (You could also use int.TryParse if you want to handle situations where it cannot actually parse the value).

So your two lines become:

cur_col3 = int.Parse(objDS1.Tables["dis_table1"].Rows[k][1].ToString()); 
cur_D_id = int.Parse(objDS1.Tables["dis_table1"].Rows[k][2].ToString());

Open in new window

0
All Courses

From novice to tech pro — start learning today.