Hi everybody!

I am attempting to sort a datatable... with no success so far! I am enclosing a sample code. Can anyone see what I am doing wrong?

TIA for your help!

mc

Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Try
            Dim dt As DataTable = New DataTable()
            Dim dr1 As DataRow, dr2 As DataRow, dr3 As DataRow
            Dim sMessage As String = ""
            Dim dv As DataView
            'define structure of datatable
            dt.Columns.Add("Student")
            dt.Columns.Add("Score")
            dt.Columns.Add("Exam date")
            'add data to datatable
            dr1 = dt.NewRow()
            dr1(0) = "Ana" : dr1(1) = 60 : dr1(2) = "01/12/2007"
            dt.Rows.Add(dr1)
            '
            dr2 = dt.NewRow()
            dr2(0) = "Berta" : dr2(1) = 70 : dr2(2) = "01/12/2007"
            dt.Rows.Add(dr2)
            '
            dr3 = dt.NewRow()
            dr3(0) = "Carmen" : dr3(1) = 80 : dr3(2) = "01/12/2007"
            dt.Rows.Add(dr3)
            '
            For i = 0 To dt.Rows.Count - 1
                sMessage = sMessage & dt.Rows(i)(0).ToString & " -- "
            Next i
            MsgBox("Before sorting - reading datatable: " & sMessage)
            sMessage = ""
            'sort
            dt.DefaultView.Sort = "Student DESC"
            dv = dt.DefaultView
            For i = 0 To dv.Table.Rows.Count - 1
                sMessage = sMessage & dv.Table.Rows(i)(0).ToString & " -- "
            Next i
            MsgBox("After sorting - reading defaultview.table: " & sMessage)
        Catch objEx As Exception
            MsgBox objEx.Message
        End Try
    End Sub