Sorting the table data:
If we want to show the data in some order based on one column, we can show by using dataview object.

For example take same employee table, but in this case we want show all employee data in some order based on their salary.

‘dv.Sort = "salary asc" 'ascending order
‘dv.Sort = " salary desc" 'descending order

                 Dim con As New SqlConnection("your database connection string")
                Dim sqldad As New SqlDataAdapter("select * from emp1", con)
                Dim ds As New DataSet
                sqldad.Fill(ds)

                Dim dv As New DataView
                'fill dataview object using dataset

                dv = ds.Tables(0).DefaultView

                'sorting
               ‘ dv.Sort = "salary" 'ascending order (default)
                dv.Sort = " salary desc" 'descending order
                
                gv1_sort.DataSource = dv
                gv1_sort.DataBind()

             

If there is no order , by default it takes ascending order.

Removing ParticularRows:
If we want to Remove some rows based on row index, we can delete.

For example, if you want to delete rows 3,4 from employee table, then
dv.Table.Rows[0].Delete();
dv.Table.Rows[1].Delete();

                 Dim con As New SqlConnection("your database connection string")
                Dim sqldad As New SqlDataAdapter("select * from emp1", con)
                Dim ds As New DataSet
                sqldad.Fill(ds)

                Dim dv As New DataView
                'fill dataview object using dataset

                dv = ds.Tables(0).DefaultView

                'removing 3,4 record
                dv.Table.Rows(3).Delete()
                dv.Table.Rows(4).Delete()
                
                gv1_delete.DataSource = dv
                gv1_delete.DataBind()
             

Finding the particular rows:
In some scenrio we want to find particular row data based on row index.
From employee table,if we want to find employee details at row 4 Then dv.find(4)

                Dim con As New SqlConnection("your database connection string")
                    Dim sqldad As New SqlDataAdapter("select * from emp1", con)
                    Dim ds As New DataSet
                    sqldad.Fill(ds)

                   
                    Dim dv As New DataView
                    'fill dataview object using dataset

                    dv = ds.Tables(0).DefaultView

                    Response.Write(dv.Find(4))    
             

In this way we can use dataview object to Filter, Removing, Sorting the table data


<< Previous Download source code here

Recent Articles

CLR integartion in SQL Server
Create, Read and Write Files in .Net
Message Queue in .Net
Deploy Asp.Net Web Site
Queues in Vb.Net
If you have any queries or doubts post at Forum
Share on Facebook
Responses(post your response or comments below)
Name *

Email * (won't be published)

Response *