Filter Data

Discussion in 'ASP .Net' started by ruca, Mar 3, 2004.

  1. ruca

    ruca Guest

    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
    ruca, Mar 3, 2004
    #1
    1. Advertising

  2. <snip>
    > dsMrc.Tables("Mrc").Select(strFilter)

    <snip>
    > 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
    Martin Dechev, Mar 3, 2004
    #2
    1. Advertising

  3. ruca

    Felbrigg Guest

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

    "ruca" <> wrote in message
    news:...
    > 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
    >
    >
    Felbrigg, Mar 3, 2004
    #3
  4. ruca

    ruca Guest

    forget FindUser :). In fact it's comment

    ruca

    "Felbrigg" <> escreveu na mensagem
    news:...
    > Maybe I'm missing something, but in the posted code, i dont think the
    > "Finduser" variable is set.
    >
    > "ruca" <> wrote in message
    > news:...
    > > 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
    > >
    > >

    >
    >
    ruca, Mar 3, 2004
    #4
  5. ruca

    ruca Guest

    But, how can I put it into a DataGrid?

    "Martin Dechev" <> escreveu na mensagem
    news:...
    > <snip>
    > > dsMrc.Tables("Mrc").Select(strFilter)

    > <snip>
    > > 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
    >
    >
    ruca, Mar 3, 2004
    #5
  6. ruca

    ruca Guest

    The way I'm doing, nothing appears and I have Data there.


    "Martin Dechev" <> escreveu na mensagem
    news:...
    > <snip>
    > > dsMrc.Tables("Mrc").Select(strFilter)

    > <snip>
    > > 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
    >
    >
    ruca, Mar 3, 2004
    #6
  7. Ruca:


    "ruca" <> wrote in message
    news:...
    > 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
    William Ryan eMVP, Mar 3, 2004
    #7
  8. Could be like this....

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


    "ruca" <> wrote in message
    news:...
    > 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
    >
    >
    Carlos Campos, Mar 3, 2004
    #8
  9. ruca

    ruca Guest

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

    I understand your code, but not show.

    Ruca


    "Carlos Campos" <carlos@(NoSpam)costarricense.cr> escreveu na mensagem
    news:...
    > Could be like this....
    >
    > Dim v as new DataView()
    > v.table = dsMrc.Tables("Mrc")
    > v.RowFilter = "Id=" & FindUser
    > dgMarcacoes.DataSource = v
    >
    >
    > "ruca" <> wrote in message
    > news:...
    > > 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
    > >
    > >

    >
    >
    ruca, Mar 3, 2004
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joey Durham

    Filter Data Grid With calendar control

    Joey Durham, Jul 5, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    631
    David Waz...
    Jul 6, 2003
  2. Brad
    Replies:
    3
    Views:
    1,870
    Steven Cheng[MSFT]
    Feb 19, 2004
  3. RyanG
    Replies:
    0
    Views:
    487
    RyanG
    Aug 23, 2004
  4. Craig G
    Replies:
    3
    Views:
    595
    Ken Cox [Microsoft MVP]
    Feb 18, 2005
  5. zax75
    Replies:
    1
    Views:
    1,095
Loading...

Share This Page