Filter Datatable by Rows
If you need to get subset of a big dataset into datatable Rowwise …
[sourcecode language='vb']
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
[/sourcecode]
Filter Datatable by Column
If you need to get subset of big dataset into datatable columnwise…
[sourcecode language='vb']
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″)[/sourcecode]