Does anyone know the best way to create a SQL Server CE (Compact 3.5) table based on the schema of a DataTable at runtime? I don’t want to have to formulate a CREATE TABLE statement based on all the different possible datatypes, etc.
As a bonus – do you then know how to fill it directly from a datatable?
I coded a reasonable solution, but was hoping to avoid case statements for the SQL types:
Firstly a neat trick to convert from a .NET type to a SqlDBType:
A case statement for the types for use in SQL Statements:
Then finally the CREATE TABLE statement: