Read in Fixed-with text file

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

Hi All,

Is there a way to read in a fixed-width ASCII text file
to a DataSet in ADO.NET? Or maybe to an ArrayList?

Thanks,
Steve
 
¤ Hi All,
¤
¤ Is there a way to read in a fixed-width ASCII text file
¤ to a DataSet in ADO.NET? Or maybe to an ArrayList?

Yes, you can but you would need a schema.ini file:

Dim ConnectionString As String

ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & "E:\My Documents\TextFiles" & ";" & _
"Extended Properties=""Text;HDR=NO;"""

Dim TextConnection As New System.Data.OleDb.OleDbConnection(ConnectionString)
TextConnection.Open()

Dim da As New System.Data.OleDb.OleDbDataAdapter("SELECT * FROM FileNames.txt",
TextConnection)

Dim ds As New DataSet("TextFiles")
da.Fill(ds, "FileNames")

Schema.ini file contents:

[FileNames.txt]
ColNameHeader=False
CharacterSet=ANSI
Format=FixedLength
Col1=OrderNumber Text Width 9
Col2=FileName Text Width 100

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/odbcjetsdk_98.asp


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
Back
Top