locked
Filtering A Dataset / Table Adapter - Accordian RRS feed

  • Question

  • User828474466 posted

    Hi

     

    Could anyone help with filtering data in a Dataset / Table Adapter ?

     

    I am using an accordian to display the details of a knowledge base, but I want to add a search feature, the code I have to display the data is :

     

    If Not IsPostBack Then
    
                Try
    
                    Dim tbl As New DataSet1TableAdapters.tipsTableAdapter
    
                    Dim dt As New DataTable
    
                    Dim ds As New DataSet
    
                    dt = tbl.GetData()
    
                    ds.Tables.Add(dt)
    
                    pds.DataSource = ds.Tables(0).DefaultView
    
                    pds.CurrentPageIndex = 0
    
                    InitPagedDataSource()
    
                Catch ex As Exception
    
                    Response.Write(ex.ToString)
    
                End Try
    
            Else
    
    
    
                pds = CType(Session("NewList"), PagedDataSource)
    
    
            End If
     
    If someone could tell me th best way about doing this that would be great !
     
    Cheers
     
    Andy
    Tuesday, August 2, 2011 5:01 AM

Answers

  • User-915072380 posted

    Try 
     
               
    Dim tbl As New DataSet1TableAdapters.tipsTableAdapter 
     
               
    Dim dt As New DataTable 
     
               
    Dim ds As New DataSet 
               
    Dim dv As DataView 
     
                dt
    = tbl.GetData() 
     
                ds
    .Tables.Add(dt) 
                dv
    = New DataView(ds.Tables(0), "Long_Text  = " + Searcher.Text, "", DataViewRowState.CurrentRows) 
                pds
    .DataSource =dv 
                    pds
    .databind() ' assuming pds it gridview or needs databind
                pds
    .CurrentPageIndex = 0 
               
    InitPagedDataSource() 
     
           
    Catch ex As Exception 
     
               
    Response.Write(ex.ToString) 
     
           
    End Try

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 3, 2011 10:09 PM

All replies

  • User2032267397 posted

    To fiulter datatable use Dataview

    use rowfilter property of datavierw

    http://www.csharp-examples.net/dataview-rowfilter/    check this link

    Regards

    Aswin Menon K

    Tuesday, August 2, 2011 5:44 AM
  • User-848116622 posted

    You can use filter in DataView

    DataView dv =ds.Tables(0).DefaultView
    dv.RowFilter="X=4 and y=4"

     pds.DataSource = dv

    Tuesday, August 2, 2011 5:47 AM
  • User828474466 posted

    Hi Thanks for your replies I have got this far but nothing is being returned ....could you shou me where I am going wrong,

     

    I have a search box called "Searcher" to search a text box called Long_Text  

     

    Thanks

     

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
            Try
    
                Dim tbl As New DataSet1TableAdapters.tipsTableAdapter
    
                Dim dt As New DataTable
    
                Dim ds As New DataSet
                Dim dv As DataView
    
                dt = tbl.GetData()
    
                ds.Tables.Add(dt)
                dv = New DataView(ds.Tables(0), "Long_Text" = Searcher.Text, "", DataViewRowState.CurrentRows)
                pds.DataSource = dv
                pds.CurrentPageIndex = 0
                InitPagedDataSource()
    
            Catch ex As Exception
    
                Response.Write(ex.ToString)
    
            End Try
    
    Tuesday, August 2, 2011 8:16 AM
  • User3866881 posted

    pds.DataSource = dv

    Hello:)

    Plz notice this:)

     pds.DataSource = dv.ToTable();   //You should call this, which will return you a result of copied, filtered datatable instance.

    Wednesday, August 3, 2011 9:45 PM
  • User-915072380 posted

    Try 
     
               
    Dim tbl As New DataSet1TableAdapters.tipsTableAdapter 
     
               
    Dim dt As New DataTable 
     
               
    Dim ds As New DataSet 
               
    Dim dv As DataView 
     
                dt
    = tbl.GetData() 
     
                ds
    .Tables.Add(dt) 
                dv
    = New DataView(ds.Tables(0), "Long_Text  = " + Searcher.Text, "", DataViewRowState.CurrentRows) 
                pds
    .DataSource =dv 
                    pds
    .databind() ' assuming pds it gridview or needs databind
                pds
    .CurrentPageIndex = 0 
               
    InitPagedDataSource() 
     
           
    Catch ex As Exception 
     
               
    Response.Write(ex.ToString) 
     
           
    End Try

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 3, 2011 10:09 PM