hi,
getting error "output table is not in correct format" can somebody tell me why ?? i am providing my code here..
where excel1 is name of excel file,
tb_excel is name of database table which have two column (id, name)
Sheet1 has data in two fileds id, name
try
{
SqlConnection sqlconnection = new SqlConnection("Data Source=.;Initial Catalog=demo_db;Integrated Security=true");
string strSource = @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\e_diary_old_style\excel1.xlsx; Extended Properties=""Excel 8.0;HDR=YES;""";
OleDbConnection sSourceConnection = new OleDbConnection(strSource);
sqlconnection.Open();
using (sSourceConnection)
{
string sqlInsert = string.Format("select id,name from [{0}]", "Sheet1$");
OleDbCommand cmd = new OleDbCommand(sqlInsert, sSourceConnection);
sSourceConnection.Open();
using (OleDbDataReader dr = cmd.ExecuteReader())
{
SqlBulkCopy bulkCopy = new SqlBulkCopy(sqlconnection);
bulkCopy.DestinationTableName = "tb_excel";
bulkCopy.WriteToServer(dr);
}
}
}