Using OLEDB to read fixed length text files, and schema.ini

cjard

Well-known member
Joined
Apr 25, 2006
Messages
7,081
Programming Experience
10+
I have a brief question:

Can the OLE data provider (in text driver mode) be used to read a text file such that lines may be one or more conceptual tables?

For example, I get one file off a guy that has a header, detail and footer line

I want this to be 3 tables. Can the driver parse individual lines out as separate tables, or must I split the file into 3 files, one per table (one line per file)?
 
OK, i've solved this by making a custom parser after some inspiration from codeproject projects.

It is implemented as a StreamReader subclass, whereby it uses a bank of regular expressions to match patterns in the data and replace them with other patterns.

As a result, it can be used to match pretty much anything that a regular expression can read and parse. Additionally, the count of lines seen by each regular expression so far, can be subbed in.

All in, I was thus able to use this to turn a fixed width flat file into XML.. Because it works as a reader, it can be used as the datasource for a DataSet.ReadXml() call, meaning that flat files can be read straight into a DataSet once the regular expressions are set up correctly.

I also wrote a tool that helps the user write the necessary regular expressions, naming the fields in the fixed width file and specifying their width. Remember; this class can pretty-much convert any text file into any other text file on the fly, its not limited to fixed width to xml conversion

If you think this class would be of some use to you, I'd be more than happy to supply it.. Ask a question in this thread, or send me a private message
 
Back
Top