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?
Asked
Active
Viewed 601 times
0
-
Does this answer your question? [Creating a SQL Server table from a C# datatable](https://stackoverflow.com/questions/1348712/creating-a-sql-server-table-from-a-c-sharp-datatable) (look past the accepted answer). ā Jeroen Mostert Nov 29 '20 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 requirement ā lars2080 Nov 30 '20 at 13:09