Import multiple related Excel Files into SQL Server with asp.net/c#
Posted on 2013-12-04
I have 4 excel files that I would like to import into a SQL Server database using and asp.net web form. Each of the 4 excel sheets go into 4 different (but related) tables. The excel file records each have an ID field, so you can see which records are related from excel file to excel file. That ID field is not in the SQL Server tables. They have an ID field, but the values are not the same between excel and sql server. Each record will get a new SQL id once it's imported. If this was just one sheet it would not be a problem. But excel file 1 needs to be imported, then each of the other 3 files with related records (but now with a new ID that does not match the SQL id). Is there a way to import by cycling through each record from all files? So the first record in excel file 1 (the parent) is imported into SQL Server and assigned a new ID, then each related record is imported from the other 3 files into their correct tables with the new SQL ID. The on to the next record. It seems quite cumbersome to me. Can something be worked out? Any help is appreciated.