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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Carl TawnSystems 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.