So I\'m in the verge of creating my first C# system. I use my vb.net system to use as my reference.
This is the code on my vb.net system:
Dim value A
Try this...
int value = int.Parse(dt.Rows[0]["TransID"]);
You could also try the Field Method on DataRow which would look like this:
int value = dr.Rows[0].Field<int>("TransID");
http://msdn.microsoft.com/en-us/library/system.data.datarowextensions.field
The line should read
int value = double.Parse(dt.Rows[0]["TransID"].ToString());
dt.Rows[0]
returns the first row, dt.Rows[0]["TransID"]
returns the value of the "TransID" column as object
from the first row. As Parse
only takes strings, not objects, you need ToString()
as well.
To avoid ToString
you could also use the following, which is even better:
int value = (int)Convert.ToDouble(dt.Rows[0]["TransID"]);
int value = int.Parse(dt.Rows[0]["TransID"]);
or you can also use column index if you know it:
Assuming that required column is 3rd column in the datatable:
int value = int.Parse(dt.Rows[0][2]);
Try this:
int value = double.Parse(dt.Rows[0]["TransID"]);
dt.Rows[0]["TransID"]
This should be working.