I have a requirement to dynamically create a SQL table based on user uploads of tab delimited files and then insert the contents. I'm using .NET Core / MVC and am able to process the files using the DataTable class, but finding it very awkward to export the .NET DataTable to a (MS) SQL database. I thought there would be some equivalent .NET function of the pandas TO_SQL. Whilst SqlBulkCopy works for inserts into previously defined tables, from what I have read, there is no way to create the table if it does not exist. So my question is, is there a way to create this table dynamically based on the datatable object?
-
Does this answer your question? Creating a SQL Server table from a C# datatable (look past the accepted answer).Jeroen Mostert– Jeroen Mostert2020-11-29 12:02:03 +00:00Commented Nov 29, 2020 at 12:02
-
Hi jeroen, thanks. The link is helpful but not necessarily dynamic. I extended the code provided and am generally pretty happy but would have preferred a native solution to what I’m sure is a relatively common requirementlars2080– lars20802020-11-30 13:09:41 +00:00Commented Nov 30, 2020 at 13:09
Add a comment
|