bartteems
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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!
ASKER
it works, thanks