View Single Post
  #1 (permalink)  
Old 11-22-2008, 10:25 PM
victor64 victor64 is offline
VB.NET Forum Enthusiast
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Nov 2008
Age: 46
Posts: 52
Reputation: 20
victor64 is on a distinguished programming path ahead
Default Help with Sorting data in a row

Hello,

I'm getting the right order but the old data is still in the row, for example the row shows duplicate data with the old and new sort order. "USA,BEL,DEU,CANBEL,CAN,DEU,USA" Can you please help me fix the code.

Thanks

Code:

Code:
        Try 
            'conn.Open() 
            Dim cmd As New OleDbCommand("SELECT ID, country FROM Identification_data", objConnection) 
            Dim dr As OleDbDataReader = cmd.ExecuteReader 
            Dim intIndex As Integer 
            Dim arrFields As New ArrayList 
            Dim arrIds As New ArrayList 
            Dim sortedList As String 

            While dr.Read 
                intIndex = dr("id").ToString 
                sortedList = dr("COUNTRY").ToString 
                ' myString = dr("country").ToString() 
                Dim spliter() As String = sortedList.Split(",") 
                Array.Sort(spliter) 
                For i As Integer = 0 To spliter.Length - 1 
                    If i < spliter.Length - 1 Then 
                        sortedList &= spliter(i).ToString & "," 
                    Else 
                        sortedList &= spliter(i).ToString 
                    End If 
                    arrFields.Add(sortedList) 
                    arrIds.Add(intIndex) 
                Next 
            End While 
            dr.Close() 
            For i As Integer = 0 To arrFields.Count - 1 
                Dim updCmd As New OleDbCommand("UPDATE identification_data SET country ='" & arrFields(i).ToString & "' WHERE id=" & arrIds(i).ToString & "", objConnection) 
                updCmd.ExecuteNonQuery() 
                updCmd.Dispose() 
            Next 
        Catch ex As Exception 
            MsgBox("LLLL") 
            MessageBox.Show(ex.Message) 
        Finally 
            objConnection.Close() 
            MsgBox("END") 
        End Try

Last edited by JohnH; 11-23-2008 at 5:21 AM. Reason: formatted post for readability
Reply With Quote