Script(s)

what I learn is what u c

Posts Tagged ‘Ado.Net

Asp.Net Filter Datatable by Column

with 6 comments

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")
Advertisements

Written by gchandra

January 7, 2008 at 4:13 pm