CSV file having multiple columns how to split between respective multiple tables
Eg: Sample1.csv file having :Id,Department,Name -Read from these csv file column to write 2 different tables and column names varies like Id in Sample1 file but in table1 it is EmpId
Sample2.csv file having :Id,Name,Address,Qualification -Read from these csv file column to write 2 different tables and column names varies like Name in Sample2 file but in table2 it is EmpName
Table 1 : EmpId,EmpDepartment,EmpName
Table2 :EmpId,EmpName,EmpAddress,EmpQualification
Tuhin PaulPosted Mar 15, 2023, 4:39 AM
Hello Meghana,
To split the columns of the CSV files into respective tables in C#, you can use the following code
Sample2.csv:
The code above reads the CSV file into a DataTable, creates two new DataTables with the desired column names, populates the tables with the data from the CSV file, and then prints the tables to the console.
Assuming that the CSV files are in the same format as described in the question. If the CSV files have different column names or different numbers of columns, the code will need to be modified accordingly.
Vishal YelvePosted Mar 13, 2023, 5:32 AM
Hi Meghana,
https://www.c-sharpcorner.com/article/how-to-read-data-from-an-excel-sheet/
Amit MohantyPosted Mar 13, 2023, 4:24 AM
Check this.
Jignesh KumarPosted Mar 13, 2023, 3:40 AM
Hello Meghana,
you can use Import wizard of sql server to import csv filr into sql table,
https://www.c-sharpcorner.com/article/how-to-import-data-from-excel-data-into-sql-table/