0

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 !

4
Contributors
4
Replies
24
Views
3 Years
Discussion Span
Last Post by M.Waqas Aslam
0

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.

Edited by JorgeM

0

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.

0

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

Regards

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.