Re: Help please! Filtering datatable filled by excel file.
Without having read your code, I'd say the best way to filter is to use a DataView. You can bind to a DataView just like a DataTable. In fact, it may be the case that binding to a DataTable actually binds to that table's DefaultView. I'm sure there are others more knowledgeable than I who will confirm or deny this.
Re: Help please! Filtering datatable filled by excel file.
A DataView behaves more like a DataRowCollection than a DataTable. As an example, to access the first row in a DataTable you would use myDataTable.Rows(0). The Rows property of a DataTable is a DataRowCollection. To access the first row of a DataView you would use myDataView(0). A DataView contains DataRowView objects, which are very similar to DataRows but not the same.
You can create a DataView for a DataTable like this:
VB Code:
Dim myDataView As New DataView(myDataTable)
or you can simply refer to the DefaultView property of the DataTable. The properties of most interest I think would be RowFilter, RowStateFilter and Sort.
RowFilter can be set to a valid SQL "where" clause to have the the view only expose the rows that match those criteria, e.g.
VB Code:
myDataView.RowFilter = "ID > 100 AND Name LIKE 's%'"
RowStateFilter can be used to hide rows that do not match a certain state or states, e.g. Added, Deleted, etc.
Sort can be set to a valid SQL "order by" clause to order the visible rows on various fields, e.g.
VB Code:
myDataView.Sort = "ID DESC, Name ASC"
I've never used one, but a DataViewManager is to a DataSet as a DataView is to a DataTable.
Re: Help please! Filtering datatable filled by excel file.
DataViews exist specifically to filter DataTables so unless you want to write some really complex code to do it all manually I'd say you're going to have to come to grips with it. Feel free (obviously) to post any specific questions or sections of code that are causing you trouble.