Convert textfile to dataset - missing column

stustarz

Well-known member
Joined
Jan 10, 2003
Messages
246
Location
Earth
Hi

I am creating a function that will take a pipe ( | ) delimited text file of 5 columns and convert it to a dataset - the code i have so far is:

Code:
    Public Function Convert(ByVal strFileName As String, ByVal dtTable As String, ByVal strDelimiter As String) As DataSet

        Dim objStreamReader As New StreamReader(strFileName)
        Dim objColumns As String() = objStreamReader.ReadLine().Split(strDelimiter.ToCharArray())
        dsResult.Tables.Add(dtTable)

        dsResult.Tables(dtTable).Columns.Add("JobNumber")
        dsResult.Tables(dtTable).Columns.Add("BatchNumber")
        dsResult.Tables(dtTable).Columns.Add("BatchRunSeqNo")
        dsResult.Tables(dtTable).Columns.Add("ImagePath")
        dsResult.Tables(dtTable).Columns.Add("RootKeyForm")

        Dim AllData As String = objStreamReader.ReadToEnd()
        Dim rows As String() = AllData.Split(ControlChars.CrLf + ControlChars.NewLine.ToCharArray())
        Now add each row to the DataSet        
        Dim r As String
        For Each r In rows
            Split the row at the delimiter.
            Dim items As String() = r.Split(strDelimiter.ToCharArray())

            Add the item
            dsResult.Tables(dtTable).Rows.Add(items)
        Next r

        Return the imported data.        
        Return dsResult

    End Function

Now..., it creates the dataset fine, BUT...the first column only displays the value once in the first row, - after that it seems to place a vbcrlf in front of the value so it is not visible unless i delete it manually from each field - you with me? basically there is something wrong in the code and i cant seem to work out where, which is causing the first column to incorrectly show the values.

Any ideas anyone?

Cheers

Stu!
 
Last edited by a moderator:
Back
Top