Filter Data

R

ruca

Hi gurus,
How can I filter data in my DataSet and then put the result in a DataGrid?
NOTE: I'm reading a txt file into a dataset with 3 columns:

Id, Name, Age

I have this:


code------------------------------------------------------------------------
-----------------------
LerLinha = New StreamReader(LerPath)

dsMrc = New DataSet
dtMrc = New DataTable("Mrc")
dcMrc = New DataColumn("Id",
System.Type.GetType("System.String"))
dcMrc = New DataColumn("Name",
System.Type.GetType("System.String"))
dcMrc = New DataColumn("Age",
System.Type.GetType("System.String"))

dtMrc.Columns.Add("Id")
dtMrc.Columns.Add("Name")
dtMrc.Columns.Add("Age")

dsMrc.Tables.Add(dtMrc)

Do
txtLine = LerLinha.ReadLine()

drMrc = dtMrc.NewRow()
drMrc("Id") = ProcessId(txtLine) 'FindUser
drMrc("Name") = ProcessName(txtLine)
drMrc("Age") = ProcessAge(txtLine)
dtMrc.Rows.Add(drMrc)

dsMrc.Tables("Mrc").Rows.Add(drMrc)
Loop Until txtLine Is Nothing

Dim strFilter As String

strFilter = "Id=" & FindUser

dsMrc.Tables("Mrc").Select(strFilter)

dgMarcacoes.DataSource = dsMrc

LerLinha.Close()
LerLinha = Nothing
code------------------------------------------------------------------------
 
M

Martin Dechev

dsMrc.Tables("Mrc").Select(strFilter)
What's wrong??????

The Select method on the DataTable class returns an array of DataRow objects
that match the filter criteria. You should use the returned array. The call
to Select doesn't modify the DataTable itself.

Greetings
Martin
 
F

Felbrigg

Maybe I'm missing something, but in the posted code, i dont think the
"Finduser" variable is set.
 
R

ruca

forget FindUser :). In fact it's comment

ruca

Felbrigg said:
Maybe I'm missing something, but in the posted code, i dont think the
"Finduser" variable is set.


code------------------------------------------------------------------------
code------------------------------------------------------------------------
 
R

ruca

But, how can I put it into a DataGrid?

Martin Dechev said:
The Select method on the DataTable class returns an array of DataRow objects
that match the filter criteria. You should use the returned array. The call
to Select doesn't modify the DataTable itself.

Greetings
Martin
 
W

William Ryan eMVP

Ruca:


ruca said:
Hi gurus,
How can I filter data in my DataSet and then put the result in a DataGrid?
NOTE: I'm reading a txt file into a dataset with 3 columns:

Id, Name, Age

I have this:


code------------------------------------------------------------------------
-----------------------
LerLinha = New StreamReader(LerPath)

dsMrc = New DataSet
dtMrc = New DataTable("Mrc")
dcMrc = New DataColumn("Id",
System.Type.GetType("System.String"))
dcMrc = New DataColumn("Name",
System.Type.GetType("System.String"))
dcMrc = New DataColumn("Age",
System.Type.GetType("System.String"))

dtMrc.Columns.Add("Id")
dtMrc.Columns.Add("Name")
dtMrc.Columns.Add("Age")

dsMrc.Tables.Add(dtMrc)

Do
txtLine = LerLinha.ReadLine()

drMrc = dtMrc.NewRow()
drMrc("Id") = ProcessId(txtLine) 'FindUser
drMrc("Name") = ProcessName(txtLine)
drMrc("Age") = ProcessAge(txtLine)
dtMrc.Rows.Add(drMrc)

dsMrc.Tables("Mrc").Rows.Add(drMrc)
Loop Until txtLine Is Nothing

Dim strFilter As String

strFilter = "Id=" & FindUser

dsMrc.Tables("Mrc").Select(strFilter)

dgMarcacoes.DataSource = dsMrc

LerLinha.Close()
LerLinha = Nothing
code------------------------------------------------------------------------
-----------------------


What's wrong??????

--

Thank's (if you try to help me)
Hope this help you (if I try to help you)
ruca

you may want to consider binding the grid to a DataView which is based on a
DataTable in your Dataset and then just changing the rowfilter. If you do
this, the filtered data will be reflected immediately. Just set the Grid's
DataSource property to the DataView and use something like this
http://www.knowdotnet.com/articles/advancedrowfilter.html
 
C

Carlos Campos

Could be like this....

Dim v as new DataView()
v.table = dsMrc.Tables("Mrc")
v.RowFilter = "Id=" & FindUser
dgMarcacoes.DataSource = v
 
R

ruca

My drop it isn't show anything, and don't know why.

I understand your code, but not show.

Ruca
 

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

View data in DataGrid 2
Put Data in DropDownList 3
Read DataSet 0
Data Grid will not display 3
Solution Required 2
datagrid not displaying data table data 2
Dataset, how to set hyperlink? 2
Data Binding Issue 0

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top