Re: Organize and Print CSV data

Tech-Archive recommends: Fix windows errors by optimizing your registry



OK, how about I simplify this. What about simply reading a CSV and
printing each record to a label? Any bits of code available for that?



Cor Ligthert [MVP] wrote:
Boo,

Why? A classic approach needs only a classic loop whatever that is (For Do
While), which can be done even direct in the reading part. The OP shows that
he/she is a newbie in Net not in programming.

That you and I probably will direct do it with OleDb and a datatable, does
not mean in my eyes that what we do is the most efficient or the best method
for this problem.

Just my thought,

Cor

"GhostInAK" <ghostinak@xxxxxxxxx> schreef in bericht
news:c71747b42d6eb8c895065dfbe98c@xxxxxxxxxxxxxxxxxxxxx
Hello Cor Ligthert [MVP],

ADO is the way to go when accessing CSV files. Field values can be quoted
or not.. which makes parsing my hand difficult, but not impossible. ADO
will simply be easier and faster than rolling your own CSV parser,
especially for a newbie.

-Boo

Boo,

I don't see where OleDB or ODBC can help the OP?

Can you explain that further, I would keep it with his own procedure.

Cor

"GhostInAK" <ghostinak@xxxxxxxxx> schreef in bericht
news:c71747b42d1f88c893691dbcbdf4@xxxxxxxxxxxxxxxxxxxxx

Hello Jchick,

This is relatively straight forward with ADO.Net. Use a
OdbcConnection/Command or OleDbConnection/Command with the
appropriate
connection string (see connectionstrings.com).
Other than that, your method looks fine.
-Boo

Boy, this should be a simple bit of code but I can't figure out how
to make it happen.

I have a CSV file shows up in a directory that has 4 fields that
need to be printed on labels. Each line of the CSV looks something
like this:

AcctNo, Name, junk, junk, Address, junk, PhoneNo

I need to read each line of the CSV and print them to Avery Label
stock (30 labels per ***, 3 columns, 10 rows). I also need them to
pull from a specific tray on the printer.

The result should look something like this:

Jim Smith Mary Smith John Doe
123 any street 50 First st 12 Maple ST
8542115 12345678 9858574
555-555-1212 555-555-1111 555-555-2222
I am thinking the steps are something like this:
1. Watch the directory for a CSV file
2. Use StreamReader to read each line of the CSV
3. Drop fields 3,4 and 6 (the Junk fields)
4. Organize fields to this order: Name, address, AcctNo, PhoneNo
5. Select the appropriate tray of a specific printer
6. Print the records in 3 rows, 10 columns.
I know Word/Excel can read a CSV, do a mailmerge and output the
labels
but my customer is interested in a VB.net solution.
Is this way too complicated? Any ideas on how to get started?

Thanks in advance.




.


Quantcast