Line 68: OleDbCommand oledbcmd = new OleDbCommand(exceldataquery, oledb); Line 69: oledb.Open(); Line 70: OleDbDataReader dr = oledbcmd.ExecuteReader(); Line 71: SqlBulkCopy bulkcopy = new SqlBulkCopy(sqlconnectionstring); Line 72: bulkcopy.DestinationTableName = sqltable;
protected void importdatafromexcel(string filepath) { string sqltable = "PFDummyExcel"; string exceldataquery = "select EmployeeId,EmployeeName,Amount from [Sheet1$]"; string excelconnectionstring = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filepath + ";Extended Properties=Excel 12.0;Persist Security Info=False"; string sqlconnectionstring = System.Configuration.ConfigurationManager.ConnectionStrings["HRGold"].ConnectionString; SqlConnection con = new SqlConnection(sqlconnectionstring); OleDbConnection oledb = new OleDbConnection(excelconnectionstring); OleDbCommand oledbcmd = new OleDbCommand(exceldataquery, oledb); oledb.Open(); OleDbDataReader dr = oledbcmd.ExecuteReader(); SqlBulkCopy bulkcopy = new SqlBulkCopy(sqlconnectionstring); bulkcopy.DestinationTableName = sqltable; while (dr.Read()) { bulkcopy.WriteToServer(dr); } oledb.Close(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)