Create table on DB along with data based on DataTable

c# sqlbulkcopy

Question

In my C# code, I have get a DataTable from excel,It has somedata.Now I want to create a table in database using this DataTable ,and insert it's data to database. How could I do it? using SqlBulkCopy?

I want to write a method like this

///using DataTable dt to create Table and insert data to this created table
public bool CreateTable(string sqlconnectionstring,DataTable dt)
{

}

Popular Answer

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



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why