Click here to Skip to main content
15,906,645 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
There is an existing csv file, with few columns and corresponding rows. a new column containing newly generated unique IDs(pulled from SQL Server) have to be added as the last column.

I used AppendAllText method of String builder. But it wont append the column at the end instead it will add the new column and its contents below the existing data.

Please help me with this.
Thank you.
Posted
Updated 13-Aug-14 23:36pm
v2
Comments
superselector 14-Aug-14 6:54am    
Would Suggest you to
1. export the csv file to DataTable
2. create a new datatable with only one column ID and add the values
3. Merge the datatables
4. Import the newly created datatable to csv file
Happy_soul 14-Aug-14 7:35am    
Thank you for response!
Yes m using the same logic,but i m not finding the proper code.
if i merge the old datatable with new one, m facing two problems :
1. the new column wont append properly in the datatable
2. if any columns are having date then automatically end up getting timestamps while they are posted in csv file. i don want timestamps
Can u please send me the code to merge the column in datatable with existing CSV.

1 solution

See whether You have the answer on this link

http://forums.asp.net/t/1979251.aspx?Add+new+column+in+existing+CSV+file+using+C+[^]

Or you can use code project article

C# CSV Reader and Writer[^]
 
Share this answer
 
Comments
Happy_soul 14-Aug-14 7:36am    
Thank you for responding!
I have checked those links. it was not useful. :(

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900