CSV file having multiple columns how to split between respective multiple tables
Eg: Sample1.csv file having :Id,Department,Name,Address,Qualification -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
Table 1 : EmpId,EmpDepartment
Table2 :Name,Address
Edwin KlesmanPosted Mar 10, 2023, 3:52 PM
Assuming the tables for the CSV columns already exist in your database and you only need to insert the records from the CSV file into the respective tables, you can modify the previous code snippet as follows:
This code snippet reads the "Sample1.csv" file into a DataTable and then inserts the records into the respective tables using parameterized SQL queries.
You will need to replace
with your actual database connection string. Note that this code assumes that the column names in the CSV file match the column names in the database tables.