CSV (or Sheet In XLS) To SQL Create (and Insert) Statements With .Net?

- 1 answer

Does anyone have a technique for generating SQL table create (and data insert) commands pragmatically from a CSV (or sheet in a .xls) file?

I've got a third party database system which I'd like to populate with data from a csv file (or sheet in a xls file) but the importer supplied can't create the table structure automatically as it does the import. My csv file has lots of tables with lots of columns so I'd like to automate the table creation process as well as the data importing if possible but I'm unsure about how to go about generating the create statement...



In SQL server it is as easy as

SELECT * INTO NewTablenNmeHere
FROM OPENROWSET( 'Microsoft.Jet.OLEDB.4.0', 
'Excel 8.0;Database=C:\testing.xls','SELECT * FROM [Sheet1$]')