Link to home
Start Free TrialLog in
Avatar of bartteems
bartteemsFlag for United States of America

asked on

How to Sort a Dataset in VB.net?

I have a dataset that I read a CSV file into and I use a reader to get access to the fields. My Question is how can I sort the data so that the reader comes out in a specific order? Thanks, Bart
Public Shared Function ReadCSVintoDataSet(ByVal strFileName As String) As DataSet
 
        Dim sConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
             Path.GetDirectoryName(strFileName) & _
             "\;Extended Properties=""text;HDR=Yes;FMT=Delimited"""
        Dim objConn As New System.Data.OleDb.OleDbConnection(sConnectionString)
        Dim da As OleDb.OleDbDataAdapter
        Dim ds As DataSet
 
        Try
            'Open Data Adapter to Read from Text file
            da = New System.Data.OleDb.OleDbDataAdapter("SELECT * FROM [" & Path.GetFileName(strFileName) & "]", objConn)
            ds = New DataSet("CSVFile")
 
            'Fill dataset using dataadapter
            da.Fill(ds, strFileName)
 
            Return ds
 
        Catch ex As Exception
            Return Nothing
            ' !!! oopsy MsgBox(ex.Message)
        End Try
 
    End Function

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of abel
abel
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bartteems

ASKER

I will give that a try, and if it works I will hit myself in the head for being silly. ;-) Thanks!

it works, thanks
Interesting, because I tried the same and couldn't get it to work, although examples (incomplete) on the internet said that it should work... I must've made some silly mistake somewhere. Glad it works for you!