how to fetch a particular field in a dataset?

G

Guest

Hi,

The dataset is filled with the queryresult like this:
sda = New SqlDataAdapter(sqlstring, ConnectString)
dt = New DataSet()
sda.Fill(dt)

Is it now possible to fetch a particular field of a particular record, like
SqlDataReader and the GetValue() method?

Thanks
 
G

Guest

Hi,

Yes, you can use
DataRow[] rows = dt.Select("CLAUSE"); //CLAUSE = like a where clause
without WHERE
//to extract a row or some rows.
if (rows!=null && rows.Length>0)
rows[0].ItemArray[x]; //where x is a index in ItemArray...

Bye
 
G

Guest

Sorry the code is for a 'DataTable dt', but you can use a DataTable in place
of your DataSet and it will work.

sebastieng said:
Hi,

Yes, you can use
DataRow[] rows = dt.Select("CLAUSE"); //CLAUSE = like a where clause
without WHERE
//to extract a row or some rows.
if (rows!=null && rows.Length>0)
rows[0].ItemArray[x]; //where x is a index in ItemArray...

Bye

a said:
Hi,

The dataset is filled with the queryresult like this:
sda = New SqlDataAdapter(sqlstring, ConnectString)
dt = New DataSet()
sda.Fill(dt)

Is it now possible to fetch a particular field of a particular record, like
SqlDataReader and the GetValue() method?

Thanks
 
C

Cor Ligthert [MVP]

a,

A dataset is a wrapper around datatables and datarelations
Datatables holds datarows and datacolumns.
Datacolumns describes the items in a datarow

Therefore
ds.tables(0).rows(0).item(0) is the first item in the first row in the first
table of your dataset ds.
However there are a lot of overloads therefore
ds.tables(0).rows(0).item("columname") gives the same.

Be aware that it are always objects that are returned in a so called non
strongly typed dataset, and therefore you have to cast even if it is with a
string with "ToSring"

I hope this helps,

Cor
 
G

Guest

Thanks

Cor Ligthert said:
a,

A dataset is a wrapper around datatables and datarelations
Datatables holds datarows and datacolumns.
Datacolumns describes the items in a datarow

Therefore
ds.tables(0).rows(0).item(0) is the first item in the first row in the first
table of your dataset ds.
However there are a lot of overloads therefore
ds.tables(0).rows(0).item("columname") gives the same.

Be aware that it are always objects that are returned in a so called non
strongly typed dataset, and therefore you have to cast even if it is with a
string with "ToSring"

I hope this helps,

Cor
 

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