0

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?

Magnetron
  • 7,495
  • 1
  • 25
  • 41
  • 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

0 Answers0