I am trying to upload individual ListObject tables in excel to SQL tables in a database.
I have already wrote code that simply generates an SQL query string and executes - this works but it's not easily maintainable.
So I found this technique: https://stackoverflow.com/a/11268550/1610402
This allows me to fill a data table and bulk insert that into SQL; with column mapping capabilities if they are required.
However my table structure in Excel differs more than simply column 'names' to avoid redundant data.
Therefore I need to map columns from Excel (example):
Column1 Column2 '2015' '2016' '2017' '2018' '2019' '2020'
1 1 0.1 0.2 0.3 0.35 0.375 0.4
1 2 0.1 0.2 0.3 0.35 0.375 0.4
To columns in SQL, like the following:
Column1 Column2 Year Value
1 1 2015 0.1
1 1 2016 0.2
1 1 2017 0.3
1 1 2018 0.35
1 1 2019 0.375
1 1 2020 0.4
1 2 2015 0.1
1 2 2016 0.2
1 2 2017 0.3
1 2 2018 0.35
1 2 2019 0.375
1 2 2020 0.4
Is there a better way of doing this in C# .Net or should I stick with my nested for loop and string builder?