move rows in a dataview

  • Thread starter Thread starter Sam
  • Start date Start date
Hi,

Sorting the dataview will reorder the records. You might have to
add a column to the datatable for sorting


Dim strConn As String
Dim ds As New DataSet
Dim strSQL As String
Dim daEmployees As OleDbDataAdapter
Dim conn As OleDbConnection
strConn = "Provider = Microsoft.Jet.OLEDB.4.0;"
strConn &= "Data Source = Northwind.mdb;"

conn = New OleDbConnection(strConn)
da = New OleDbDataAdapter("Select * From Categories", conn)
da.Fill(ds, "Categories")

Dim dcSort As New DataColumn("First", GetType(Integer))
ds.Tables("Categories").Columns.Add(dcSort)

Trace.WriteLine("Before sort")
Dim dv As New DataView(ds.Tables("Categories"))
For Each drvCategories As DataRowView In dv
Trace.WriteLine(drvCategories.Item("Description"))
Next

For Each drvCategories As DataRowView In dv
drvCategories.Item("First") = 1
Next

dv.Item(4).Item("First") = 0
dv.Sort = "First"
Trace.WriteLine("After sort")
For Each drvCategories As DataRowView In dv
Trace.WriteLine(drvCategories.Item("Description"))
Next


Ken
---------------------


Hi,
How can I move a row in my dataview to the first position ?

Thx
 
Back
Top