How to use Dataview to filter data from a datatable
In some situations,we need the extract data from datatable.Dataview can be used to filter the data from datatable.
This code shows how to use DataView to filter data from datatable.
Dim objDT As New DataTable
Dim objDV As DataView
Dim strQuery As String
'Query for filling data in datatable.
strQuery = "Select * from OITM"
'In GetData() function,query is fired and data is
'saved in objDT.
objDT = GetData(strQuery)
If objDT.Rows.Count > 0 Then
'The dataview objDV is filtered over the column
'code.All the records whose Code is BBAG are
'extracted from the datatable objDT and saved in
'dataview objDV.
objDV=New DataView(objDT,"Code='BBAG'","Code",DataViewRowState.CurrentRows)
If objDV.Count > 0 Then
'The value from 1st row and 1st column is displayed
MessageBox.Show(objDV.Item(0).Item(0))
End If
End If
Hello
Nice piece of code
Thanks for sharing your knowledge with us.
I hope to see more good code from your side
This code will help lots of guys