Asp.Net Filter Datatable by Column
Filter Datatable by Rows
If you need to get subset of a big dataset into datatable Rowwise …
Dim dtEmp as DataTable Dim dsEmployee as New DataSet dsEmployee = someobject.getdata() 'dataset can be populated in many ways which is not explained here. Dim sExpr as String Dim drRows() as DataRow, drSingleRow as DataRow sExpr = "EmpID > 100" 'Condition drRows = dsEmployee.Tables(0).Select(sExpr) 'If you need to add Sort Order it can be added to sExpr Dim sSortOrder as String sSortOrder = "EmpName DESC" drRows = dsEmployee.Tables(0).Select(sExpr,sSortOrder) For Each drSingleRow in drRows dtEmp.ImportRow(drRows) Next ' Datatable dtEmp has filtered records
Filter Datatable by Column
If you need to get subset of big dataset into datatable columnwise…
Dim dtEmp as DataTable Dim dsEmployee as New DataSet dsEmployoee = someobject.getdata() 'dataset can be populated in many ways which is not explained here. 'This copies the structure and data dtEmp = dsEmployee.Tables(0).Copy dtEmp.Columns.Remove("Unwanted Column 1") dtEmp.Columns.Remove("Unwanted Column 2") dtEmp.Columns.Remove("Unwanted Column 3")
pls let us know how to read a feed into a datatable in asp.net
swarna
January 13, 2008 at 7:57 am
This article explains it very nicely. Please take a look.
http://aspnet.4guysfromrolla.com/articles/031903-1.aspx
gchandra
January 13, 2008 at 9:27 am
thanks a lot dude
ace
December 19, 2008 at 3:56 am
Line 21 in the first example, shouldn’t it be passing drSingleRow to ImportRow?
Once dtEmp has filtered records how do I reference the columns? Will it have the same schema as the row which was imported? I’m having problem with this, cannot reference the filtered data table columns.
Kashif
March 16, 2009 at 9:25 am
Kashif,
Clone the original datatable before inserting via ImportRow, this way you can access the column names.
dtEmp = dsEmployee.Tables(0).Clone
Or
Use column numbers (0), (1)
Ganesh
March 16, 2009 at 9:31 am
Thanks, friends.
Oskar Merchan
March 25, 2009 at 3:45 pm