I consume survey data (delivered as json) from our provider via SSE and deserialize them into an Object. The object holds the following data without the header information, just the data ("1","1","Yes, I do")
|UserNumber | Variable1 | Variable2 |
|------------|-------------|--------------|
| 1 | 1 | Yes, I do |
| 1 | 5 | No, I do not|
The number of Users and the number of variables differ from survey to survey but at the moment the maximum is 500.000 and 350. The object looks as follows:
(1) User1
(1) "4482359"
(2) "12526"
(3) "5"
(4) ""
...
(2) User1
(1) "5847895"
(2) "33568"
(3) "6"
(4) "2"
...
I store the data in an object and now I want to store the data in a SQL Table but I am not sure how to do that since my object differs in length (both dimesions). What I have acomplished already is to bring the data into .csv and use Bulk Insert (even though I got problems due to the "," separator)
query.Append("USE Import BULK INSERT dbo.[Insert_Table] FROM")
query.Append(" 'C:\Users\I\Desktop\Insert_Table.csv' ")
query.Append("With (FIELDTERMINATOR = ',', ROWTERMINATOR = '\n')")
But for this I have to loop over all the elements.
I have also read about SQLBulkCopy but for that I have to bring the data into Datatable and map this one with the SQL Table. But since I do not have columnames in the object I do not see how to use this. Could anyone give me a snippet of how to insert the object into my database?