Newbie: Dataset questions

S

steve

Hi,
Is there a way to execute a SELECT statement *on* a dataset itself?
After it has been filled, without having to go through the dataadapter?

Also, hoe can one loop through the dataset?
would it be something like:
Mydataset.Tables("mytable").Rows.Count
OR is there a better way?

TIA
-steve
 
K

Kevin Hodgson

To loop through the DataRows in your DataSet.

Dim oDR as DataRow
For Each oDR in MyDataSet.Tables("mytable")
Do Stuff to oDR
Next
 
K

Kevin Hodgson

Actually, there are a couple of ways to do it. I forgot to specify the
..Rows collection at the end of the DataSet.
Dim UserRows As System.Data.DataRowCollection =
MyDataSet.Tables("mytable").Rows
Dim oDR As System.Data.DataRow
For Each oDR In UserRows
'Do stuff to oDR
Next

This will work too

Dim dt As DataTable = DsSingleShip1.Tables(0)
Dim oDR As DataRow
For Each oDR In dt.Rows
'Do stuff to oDR
Next
 
S

steve

Thanx Kevin!
Any comments on the second part?
i.e. How to apply a "SELECT" type of methodology on a dataset ?
I dont think filtering would be enough, or would it ?

-steve
 
K

Kevin Hodgson

I don't think you can do a SELECT on a dataset.

You can use Find on the Row Collection of a Table, But that will only return
a row based on the Primary Key Column.

Dim dr as DataRow
dr = MyDataSet.Tables("mytable").Rows.Find("primaryKeyValue")
 
B

Benny Raymond

Can't you do a:

myDataSet.TableName.Select("ID=1")

Would produce a list of rows within the table "TableName" where column
ID equals 1
 
S

steve

thanx both of you.
i'll investigate that second part. I am wondering how "involved" the Selct()
method can be.
 
B

Benny Raymond

not very... at least I don't think... If you find anything else out
please post it as a reply to this. From what i've been able to gather
it's just a simple COLUMN="something" No sort, or anything. If you're
use to sql, this is basically like what comes after the WHERE statement
but dumbed down i think.
 

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