none
Filtering results of a datatable RRS feed

  • Question

  • I cant quite figure out how to limit my results. The following always gives the full database. What am i doing wrong?

     

    Dim strFilter As String

    strFilter = "Status = 3 OR Status = 2 OR Status = 1"

     

    Dim DT As New DataTable

    DT = Me.CustJobDJobN_DS.JobData

    With DT

    .Select(strFilter)

    End With

    'databind the charts

    PriorityChart.DataTable = DT

    PriorityChart.DataMember = "Priority"

     

     

     

     

     

     

    Tuesday, August 28, 2007 4:53 PM

Answers

  • Although you are 'selecting' a couple of rows, you're doing nothing with the result that the Select method returns...

    Code Snippet

    DataView dataView = yourDataTable.DefaultView
    dataView.RowFilter = "Status = 3 OR Status = 2 Or Status = 1"
    PriorityChart.DataTable = dataView.ToTable()


    Notice that you're only limiting the rows in your datatable/dataview.. (And that it's very likely that all rows are fetched from the database.. Not sure if that's really requried)

    Tuesday, August 28, 2007 6:43 PM

All replies

  • How can we say something sensible if you don't even show the actual command you're using? Which sql-dbms are you using anyway? In SQL Server there is the TOP x keyword that allows you to limit the resultset to the first x rows...
    Tuesday, August 28, 2007 6:34 PM
  •  

    I guess i dont quite understand your question.

     

    I did notice a typo, and have repaired it. What you see now is exactly as it is in the program. Which returns all records in a table. The Chart uses "primary" column to create the pie chart. To visually represent the contents of the table.

     

    My problem is that I dont know how to filter DataTable results. I can filter BindingSource but have no idea if i can make the two the same. What you read now is my attempt at filtering the results of a Datatable.  But to be honest I dont even know if i am doing it right. Or what to look for as I am not that familar with this syntax.

    Tuesday, August 28, 2007 6:40 PM
  • Although you are 'selecting' a couple of rows, you're doing nothing with the result that the Select method returns...

    Code Snippet

    DataView dataView = yourDataTable.DefaultView
    dataView.RowFilter = "Status = 3 OR Status = 2 Or Status = 1"
    PriorityChart.DataTable = dataView.ToTable()


    Notice that you're only limiting the rows in your datatable/dataview.. (And that it's very likely that all rows are fetched from the database.. Not sure if that's really requried)

    Tuesday, August 28, 2007 6:43 PM