GETTING DATA FROM A DataSet ??

G

Guest

Can anyone tell me how to pull data from a dataset?

In my Page_Load function, I use the following code:

Dim str As String
Dim ds As System.Data.DataSet
Dim dt As System.Data.DataTable
Dim dr As System.Data.DataRow
Dim dc As System.Data.DataColumn

ds = UserTypeQueryMethod()

For Each dt In ds.Tables
For Each dr In dt.Rows
For Each dc In dt.Columns
if dr(dc) = "owner" then
msgbox(dc.DefaultValue.ToString())
if dc.DataType <> DBNull then
'GET THE VALUE OF THE COLUMN IN A ROW IN A
TABLE
end if
end if
Next dc
Next dr
Next dt
 
S

sloan

You are trying to treat a DataSet, as one used to treat ADODB.RecordSets.

This isn't good practice.

I'd look into the concept of "strongly typed" datasets. you can google that
and find alot of info.

If you don't want to use strongly typed datasets...then I think the issue is
the Column. I don't think this is the info itself, but rather the metadata
about the columns.
Aka, the EmpID, LastName, FirstName

and not the
123,Smith,John
234,Jones,Mary

...
 
G

Guest

Your code basically loops through each DataTable in the DataSet and get the
value of each "cell" if that "cell" is not null ---> You are pulling data
from the dataset already... :) Declare this varibale along with the others:
Dim dataPulledFromDS As String = ""
Then in the for loops, right upder the line "'GET THE VALUE OF THE COLUMN IN
A ROW IN A TABLE" put in
dataPulledFromDS = CStr(ds.Tables(dt).Rows(dr).Item(dc))
MsgBox(dataPulledFromDS)

Hope this helps,
VHD50.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top