Hi Friends,
i want to import data from excel into sql server table so i choose the c# and found a code from google
protected void btnSend_Click(object sender, EventArgs e)
{
string strconn = "Server = ERPSERVER3; Database = POMDB; User Id = sa; Password = sa;";
string path = fileuploadExcel.PostedFile.FileName;
string excelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;Persist Security Info=False";
//Create Connection to Excel work book
OleDbConnection excelConnection = new OleDbConnection(excelConnectionString);
//Create OleDbCommand to fetch data from Excel
OleDbCommand cmd = new OleDbCommand("SELECT [item_code],[item_desc],[uom],[grade],[Heads],[Moc],[variant],[Curr_Budget],[fin_yr] FROM [Sheet1$]", excelConnection);
excelConnection.Open();
OleDbDataReader dReader;
dReader = cmd.ExecuteReader();
SqlBulkCopy sqlBulk = new SqlBulkCopy(strconn);
//Give your Destination table name
sqlBulk.DestinationTableName = "pur_bud_pro_lc";
sqlBulk.WriteToServer(dReader);//Error
excelConnection.Close();
}
when i import the excel file its show Error of "Line 1: Incorrect syntax near 'COLLATE'." How to Solve that?