Question Datatable - accessing its data

Robert84

New member
Joined
Jul 11, 2008
Messages
1
Programming Experience
1-3
Hello everyone

Heres what i want to do:-

i have a datatable, it only contains one table, which only has one row in it, and 5 columns .

i want to take the value from a single field (NOT THE WHOLE ROW!) and put it in a string.

quick rant - to me this seems like a common thing to do but the msdn site has little info on this (or it is extremely hard to find). I mean, you grab the data from the DB, put it in a datatable to use, then use the data fields on the page in server controls and variables! but to do this seems stupidly complicated, and the info on how to do it is so hard to find. anyway...

thanks for any help on this

cheers guys
 
Let us assume you wish to retrieve the integer value from the column called HELLO, in the first row of MyDataTable


if your dataset is strongly typed(hopefully you did this, it's much more professional):

Dim i as Integer = myDataSet.MyDataTable(0).HELLO

For weakly typed:

Dim i as Integer = DirectCast(myDataSet.Tables("MyDataTable").Rows(0).Items("HELLO"), Integer)



Mmm.. prefer the first!
 
Last edited:
Back
Top