I am using the following code to read a .txt file into a dataset sucessfully
I am trying to alter the code to read a .csv file into a but get an error on the
oRows(intCounter) = strFields "Cannot find column 30 "
I read the .txt file by changing the strDelimiter to (vbTab)HTML Code:Dim strDelimiter As String = (",") Dim strFilePath As String = (path & "test.csv") Dim oDS As New DataSet() Dim strFields As String Dim oTable As New DataTable() Dim oRows As DataRow Dim intCounter As Int32 = 0 oDS.Tables.Add("Property") 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) oDS.Tables(0).Columns.Add(strFields) Next 'Now add in the Rows oTable = oDS.Tables(0) While (oSR.Peek() > -1) oRows = oTable.NewRow() For Each strFields In oSR.ReadLine().Split(strDelimiter) oRows(intCounter) = strFields intCounter = intCounter + 1 Next intCounter = 0 oTable.Rows.Add(oRows) End While




Reply With Quote