Filter Data

  • Thread starter Thread starter ruca
  • Start date Start date
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------------------------------------------------------------------------
 
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
 
Maybe I'm missing something, but in the posted code, i dont think the
"Finduser" variable is set.
 
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------------------------------------------------------------------------
 
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
 
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
 
Could be like this....

Dim v as new DataView()
v.table = dsMrc.Tables("Mrc")
v.RowFilter = "Id=" & FindUser
dgMarcacoes.DataSource = v
 
My drop it isn't show anything, and don't know why.

I understand your code, but not show.

Ruca
 
Back
Top