Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I convert this column value to an integer?

Tags:

c#

My C# code looks like this:

myNum = dt.Columns[0];

myNum is an integer and dt is a datatable. The value in column 0 of dt is a string ("12"), but I'd like to convert it to an integer. How can I do this? I've tried:

myNum = int.Parse(dt.Columns[0]);

...but that doesn't work. Any ideas?

like image 297
Kevin Avatar asked Apr 07 '10 12:04

Kevin


1 Answers

The values are stored in rows and not columns. Try this instead:

myNum = int.Parse(dt.Rows[0][0].ToString());
like image 144
Darin Dimitrov Avatar answered Oct 10 '22 23:10

Darin Dimitrov