Help with inport csv file in my c # program

I am trying to insert an inport csv file into my database in my winform program for C #.

for example csv file:

code  ,name    ,price
101010,computer,200$

and i did this:

char[] BI = { ',' };
string[] WI = TEMP.Split(BI);
A = WI[0].Trim().ToString();
B = WI[1].Trim().ToString();
C = WI[2].Trim().ToString();

but what can I do if the name contains (,)?

eg

code  ,name              ,price
101010,computer 12,200.00,200$

if I get this type of csv:

code    ,name                ,price
"101010","computer 12,200.00","200$"

how to handle this?

+3
source share
2 answers

Take a look at http://www.codeproject.com/KB/database/CsvReader.aspx , I believe this solves your problem.

+5
source

The best thing to do is not to collapse your own csv and use the existing free library. I recommend FileHelpers .

EDIT:

, , 2 .

+8

Source: https://habr.com/ru/post/1780275/


All Articles