Hi

I would like to insert a record from a CSV file into 2 tables, but it's line by line instead of conventional CSV separated. I am using c# and MSSQL.

My data is like this and its about 70 lines, they will be always in the same order :

AAA ( would go in table1)
BBB (table1)
CCC (table2)
DDD (table1)
EEE (table2)
FFF (table2)
GGG (table1)
HHH (table2)
III (table2)
....

How could I do that ?
Thanks !

You can easily read from a file. Use StreamReader.ReadLine. In your loop while reading, you can make a decision on which table to upload your data to. Since your pattern is predictable, you can use a variable to hold a count (counter) to make the decision on which table to write to.

Thanks Jorge ! I will start with this, I just realised its like reading a text file.

Not sure about the second link, the file is separated with comas. One file = one record. Multiple lines = multiple fields.

You can also use mssql server data import functionality. you can simply map your csv file columns with your table columns .

Regards

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.