I need to import data from an excel sheet into a database using C# WinForms. Each row is an 'Electricity Site' with a few columns of data going into the 'Sites' table. Each site also has a 'Contact' with its information (Name, Email, Phone), but that Contact may or may not exist already in the database. That contacts primary key (identity field) is a foreign key in the Sites table but the value is not known at runtime.
Here is some of the relevant data that the Excel file contains:
SiteID
ContactName
Phone
Here are the tables:
Contacts
(
ContactID (identity)
ContactName
Email
Phone
)
Sites
(
SiteKey (identity)
SiteID
ContactID (foreign key)
)
If that contacts name + email + phone doesnt already exist in the table then it needs to be created and that new identity is needed to be inserted into that row for Sites (if Contact exists already then that ContactID is needed).
What would be the best way to approach this and get the fastest results. In most cases 1000+ rows are in the Excel sheet.