Function delimitedDataSet(ByVal strDelimiter As String, ByVal strFilePath As String) As DataSet
Dim oDS As New DataSet
Dim strFields As String
Dim oTable As New DataTable
Dim oRows As DataRow
Dim intCounter As Int32 = 0
Dim oRow As DataRow()
Dim cancel As Boolean
oDS.DataSetName = "Dataset"
oDS.Tables.Add("Orders")
Dim oSR As New StreamReader(strFilePath)
'Go to the top of the file
oSR.BaseStream.Seek(0, SeekOrigin.Begin)
'Add in the Header Columns
For Each strFields In oSR.ReadLine().Split(strDelimiter.ToCharArray)
Dim FieldName As String = Trim(strFields)
oDS.Tables(0).Columns.Add(FieldName)
Next
'Now add in the Rows
oTable = oDS.Tables(0)
' Read each line in file
While (oSR.Peek() > -1)
' NewRow buffer
oRows = oTable.NewRow()
' Read each "Field" in the line
For Each strFields In oSR.ReadLine().Split(strDelimiter.ToCharArray)
' Check first field - if nothing then cancel reading the rest of the row
If intCounter = 0 Then
If strFields <> "" Then
' Read value of the field into the Field variable
Dim Field As String = Trim(strFields.Replace("""", ""))
' add Field to the NewRow buffer
oRows(intCounter) = Field
' increment field count
intCounter = intCounter + 1
Else
' nothing in field cancel the rest of the read
cancel = True
Exit For
End If
Else
' Read value of the field into the Field variable
Dim Field As String = Trim(strFields)
' add Field to the New Row Buffer
oRows(intCounter) = Field
' increment field count
intCounter = intCounter + 1
End If
Next
If cancel Then
' reset the field counter
intCounter = 0
Else
' reset the field counter
intCounter = 0
oTable.Rows.Add(oRows)
End If
End While
oSR.Close()
Return oDS
End Function
[size=2][color=#0000ff]Private[/color][/size][size=2] [/size][size=2][color=#0000ff]Sub[/color][/size][size=2] split()
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] myCSV [/size][size=2][color=#0000ff]As[/color][/size][size=2] [/size][size=2][color=#0000ff]String
[/color][/size][size=2][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] myArray() [/size][size=2][color=#0000ff]As[/color][/size][size=2] [/size][size=2][color=#0000ff]String
[/color][/size][size=2][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] i
myCSV = "One , two , three, four , five"
myArray = myCSV.Split(",") [/size][size=2][color=#008000]' Delimeter[/color][/size]
[size=2][color=#0000ff]For[/color][/size][size=2] i = 0 [/size][size=2][color=#0000ff]To[/color][/size][size=2] 4
[/size][size=2][color=#0000ff]Me[/color][/size][size=2].ListBox1.Items.Add(myArray(i))
[/size][size=2][color=#0000ff]Next
[/color][/size][size=2][/size][size=2][color=#0000ff]End[/color][/size][size=2] [/size][size=2][color=#0000ff]Sub
[/color][/size]