【问题标题】:Fixed length to datatable固定长度到数据表
【发布时间】:2023-02-22 06:44:57
【问题描述】:

如何读取固定的txt文件到数据表? (我正在使用 FileHelpers) 例如,我希望 List 的结果填充数据表:

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

【问题讨论】:

    标签: vb.net filehelpers


    【解决方案1】:
    Dim engine = New FixedFileEngine(Of Customer)()
    Dim customers As Customer() = engine.ReadFile(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "	est.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
    

    【讨论】:

    • 谢谢。如何使用博福阅读?
    【解决方案2】:

    如何使用 BeforeRead(FileHelpers)?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-30
      • 1970-01-01
      • 1970-01-01
      • 2013-03-18
      • 1970-01-01
      • 2011-05-18
      • 2012-01-18
      相关资源
      最近更新 更多