using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Data.SqlClient; using System.Data.OleDb; public partial class _Default : System.Web.UI.Page { string strConnection = ConfigurationManager.ConnectionStrings ["EmployeeConnectionString1"]"ConnectionString; protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { //Create connection string to Excel work book string excelConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Book1.xlsx; Extended Properties=""Excel 8.0;HDR=YES;"""; //Create Connection to Excel work book OleDbConnection excelConnection = new OleDbConnection(excelConnectionString); //Create OleDbCommand to fetch data from Excel OleDbCommand cmd = new OleDbCommand ("Select [Deptno],[DeptName],[DeptLoc] from [Book1$] ", excelConnection); if(excelConnection.State==ConnectionState.Closed) excelConnection.Open(); OleDbDataReader dReader; dReader = cmd.ExecuteReader(); SqlBulkCopy sqlBulk = new SqlBulkCopy(strConnection); sqlBulk.DestinationTableName = "Dept"; sqlBulk.WriteToServer(dReader); } }
OleDbException was unhandeled by user,cannot update database or object is read-only
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)