Does anybody know any good free third-party CSV parser modules? I am surprised that MSDN does not have any classes to parse CSV, it is so common procedure.
As DaZZleD said, I think you can write your own procedure. In some languages , for instance Perl, the work could be done in few lines. The Split() function is a candidate.
But there is another way to query data from the CSV files (like you do with tables from a database) using the ODBC Microsoft Text Driver – which is installed automatically if you have MSWord installed.
The following should be done:
-create a DSN file for the ODBC Text Driver to point to the folder where csv files are stored
-create a schema.ini file in which each csv file will have a section that describes the record structure (see below)
- If you do reporting, then use Crystal Reports to point to that ODBC and perform queries like you do in any database. The csv files are seen as tables and you can have primary key, links etc…
- If you are not interested for reporting then you can query data using OdbcDataAdapter or OdbcCommand, and DataSet.
Example of query ( LPM_DAT is an alias table from the localpayments.dat file:
SELECT
LPM_DAT.`PAYMENT_DEST`, LPM_DAT.`DATE`, LPM_DAT.`LOCATION`, LPM_DAT.`CASHIER`, LPM_DAT.`DRAWER`, LPM_DAT.`PAYMENT_AMOUNT`, LPM_DAT.`PAYMENT_METHOD`, LPM_DAT.`TIME`, LPM_DAT.`CUST_ACCOUNT`, LPM_DAT.`BILLING_NUMBER`, LPM_DAT.`CUSTOMER_NAME`
FROM
` localpayments.dat ` LPM_DAT
WHERE
LPM_DAT.`PAYMENT_METHOD` = '1'
ORDER BY
LPM_DAT.`LOCATION` ASC,
LPM_DAT.`DRAWER` ASC,
LPM_DAT.`CASHIER` ASC
Thank you very much for detailed response. It looks like a good idea when you want to manulaly create chema for every file. I am looking for something that can parse generic unknown format csv files. I think I will give up looking for the library and create my own.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.