Feb 9, 2011

how to filter data in dataset

Solution 1 (RowFilter)
Dim ds As New Data.DataSet
Dim CN As New SqlClient.SqlConnection(MyClass1.ConnStr)
Dim Stmt As String
Stmt = "select * from USER_MASTER"
Dim DA As New SqlClient.SqlDataAdapter(stmt, CN)
DA.Fill(ds, "USER_MASTER")
ds.Tables("USER_MASTER").DefaultView.RowFilter = "DEPT ='ADMIN'"
MsgBox(ds.Tables("USER_MASTER").DefaultView.Count)


Solution 2 (Select)
Dim ds As New Data.DataSet
Dim CN As New SqlClient.SqlConnection(MyClass1.ConnStr)
Dim Stmt As String
Stmt = "select * from USER_MASTER"
Dim DA As New SqlClient.SqlDataAdapter(stmt, CN)
DA.Fill(ds, "USER_MASTER")
Dim R() As DataRow
R = ds.Tables("USER_MASTER").Select("DEPT ='ADMIN'", "EMP_NAME")
If R.Length > 0 Then
MsgBox(R.Length & " Record(s) Found")
End If
In the sample code it shows the number of records found for dept called "ADMIN",

No comments:

Post a Comment

What is the use of n-tier architecture and 3-tier architecture?

how to implement 3-tier architecture in asp.net using c#. 3-Tier architecture is also called layered architecture. Some people called it ...