Get value from column in dataTable

  • Thread starter Thread starter Jim P.
  • Start date Start date
J

Jim P.

I must be missing something. Cause I'm adding a new item to a dataTable and
I need to increment a specific column. so How do I get the value of a
COLUMN within the last ROW in a DATATABLE belonging to a DATASET?

For example:
dataSet1.Table["Tasks"].Rows[lastRowID].Column["taskID"].Value.ToString();

** I know this doesn't work, but you get the idea.

Thanks a bunch.
 
Jim,

You are pretty close to doing what you need. First remember that what I
am about to show you, returns an object and there for you will need to
provide explicit typecasting to get the correct type. To adapt the example
you provided you would do like this (assuming taskID is an int):

int taskID = (int)dataSet1.Table["Tasks"].Rows[lastRowID]["taskID"].

Now you have the value of the taskID column, for the row lastRowID in
an int variable. Also note that you state that you need to increment a
specific column, and if you make that column autoincrement, then it will
be managed by the datatable if you use the NewRow() method on the
DataTable.

Hope this helps,

//Andreas
 
Back
Top