Filtering a Dataset

S

Shahriar

I am using the following statement to filter a dataset.

ds.Tables(0).DefaultView.RowFilter = "ID='" & currentpos & " '
It seems to run fine. My question is since I have a filter set, why is the
following loop still goes through every record.

How can I achieve a real filter on a dataset? I dont want to create a
dataview.


For i = 0 To ds.Tables(0).Rows.Count - 1
MsgBox(ds.Tables(0).Rows(i)("casenumber"))
Next


Many thanks
 
J

Jay B. Harlow [MVP - Outlook]

Shahriar,
You set the filter on the DataView object that DefaultView returns. This
DataView does not in any way effect the rows that are in the DataTable.
DataTable.Rows always returns all the rows in the DataTable.
I dont want to create a dataview.
You just did, with this statement.
ds.Tables(0).DefaultView.RowFilter = "ID='" & currentpos & " '

How can I achieve a real filter on a dataset?
What I normally do is use DataTable.Select when a DataView is not
"appropriate" but I want to filter the rows of a table.

Something like:

For Each row As DataRow in ds.Tables(0).Select("ID='" & currentpos &
"'")
MessageBox.Show(row("casenumber")
Next

Hope this helps
Jay
 
S

Shahriar

Jay.
Thanks for the reply. Here is my problem .
I have a dataset in a grid type layout. The user clicks on a record. There I
launch a new form displaying details on the data.
In the new form i have a text box that I want am binding to the dataset.
The issue is it has no way of knowing which row # the dataset is. That is
why I wanted to filter on the dataset itself.

tempTable = ds.Tables(0)

TextBox1.DataBindings.Add("text", tempTable, "casenumber") ' always points
to the first record.

Where in the above example can I specify the row number of the dataset for
the binding.

If I dont do databinding I would have something like this which works fine,
but I want to avoid reassining the value back.

TextBox1.Text = tempTable.Rows(currentpos)("casenumber")

Thanks

Shahriar
 
C

Cor Ligthert

Shahriar,

For that is databinding and the currencymanager something as
\\\
dim cma As CurrencyManager
textbox1.DataBindings.Clear()
cma = DirectCast(BindingContext(dv), CurrencyManager)
textbox1.DataBindings.Add(New Binding("Text", dv, "MyfieldName"))
///

I hope this gives a starting idea

Do not forget when you want to a update first to do the
\\
BindingContext(dv).EndCurrentEdit()
///
I hope this helps a little bit?

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

Similar Threads


Top