none
READING TEXT FILE TO DATAREADER RRS feed

  • Question

  • I TRY TO READ A TEXT FILE INTO DATAREADER WITH THIS CODE:

     

    Public NotOverridable Overrides Sub FillDataTableWithRowsForTemporeryTbl()

     

    ' ini
     

    buildIniFile()

     

    ' conn
     

     

    Dim MyConnection As New System.Data.OleDb.OleDbConnection( _

     

    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" & m_pathFileName & "';Extended Properties='text;HDR=NO;FMT=Delimited(" & m_delimiter & ")\';Jet OLEDB:Engine Type=96;")

     

    ''Using MyCommand As New System.Data.OleDb.OleDbDataAdapter("select * from " & m_fileName, MyConnection)
     

     

    Dim MyCommand As New OleDbCommand("select * from " & m_fileName, MyConnection)

     

    Try

    MyConnection.Open()

     

    Dim dt As New DataTable

     

    Dim reader As OleDbDataReader

    reader = MyCommand.ExecuteReader()

     

    MyBase.copyDataTableToTemporeryTbl(reader)

     

    Catch ex As Exception

     

    Throw ex

     

    Finally

    MyConnection.Close()

    MyConnection.Dispose()

     

    End Try

     

     

    End Sub

     

    ' ini

     

    Private Sub buildIniFile()

     

    ' , ini-

     

    If File.Exists(m_pathFileName & "schema.ini") Then

    File.Delete(m_pathFileName &

    "schema.ini")

     

    End If

     

    ' , ini-

     

    Dim sTxtForIniFile() As String

     

    ReDim sTxtForIniFile(155)

    sTxtForIniFile(

    0) = "[" & m_fileName & "]"

    sTxtForIniFile(

    1) = "ColNameHeader = False"

    sTxtForIniFile(

    2) = "CharacterSet = ANSI"

    sTxtForIniFile(

    3) = "MaxScanRows = 1000"

    sTxtForIniFile(

    4) = "Format=Delimited(" & m_delimiter & ")"

     

     

    For i = 13 To 150

    sTxtForIniFile(i +

    4) = "Col" & i & "=sfn_column_" & i & " char "

     

    Next i

    File.WriteAllLines(m_pathFileName &

    "schema.ini", sTxtForIniFile)

     

    End Sub

    it's work good.

    my problem is that if one of the text data field in the text file contain quotation marks the fields line not loaded good.

    all the fields in that line after the field with the quotation marks got the value null.

    can sombody help me please?

    • Moved by edhickey Thursday, August 25, 2011 2:02 PM (From:.NET 3.0/3.5 Windows Workflow Foundation)
    Thursday, August 25, 2011 10:38 AM

All replies

  • Could you post a couple of lines from your text file that contain the quotation marks?


    Paul ~~~~ Microsoft MVP (Visual Basic)
    Thursday, August 25, 2011 3:24 PM