Fixed length to datatable

73 Views Asked by At

How to read fixed txt document to datable? (I'm using FileHelpers) For example, I want results from List populate datatable:

Dim engine = New FixedFileEngine(Of Customer)()
Dim List As Customer() = engine.ReadFile(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) &
                                                   "\test.txt")



    <FixedLengthRecord(FixedMode.AllowMoreChars)>
    Public Class Customer
        <FieldFixedLength(2)>
        Public CustId As String

        <FieldFixedLength(34)>
        Public Name As String

        <FieldFixedLength(70)>
        Public ID As String
    End Class
1

There are 1 best solutions below

1
Thilina Mullewidane On
Dim engine = New FixedFileEngine(Of Customer)()
Dim customers As Customer() = engine.ReadFile(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\test.txt")



Dim table As New DataTable()


table.Columns.Add("CustId", GetType(String))
table.Columns.Add("Name", GetType(String))
table.Columns.Add("ID", GetType(String))



Dim row As DataRow = table.NewRow()
row("CustId") = customer.CustId
row("Name") = customer.Name
row("ID") = customer.ID
table.Rows.Add(row)

DataGridView1.DataSource = table