0

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)
{

}
sujith karivelil
  • 28,671
  • 6
  • 55
  • 88
elsonwx
  • 1,431
  • 3
  • 16
  • 26
  • 1
    This is bad practise ! Read this question http://stackoverflow.com/questions/1348712/creating-a-sql-server-table-from-a-c-sharp-datatable – mybirthname Aug 19 '15 at 02:31

1 Answers1

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