strConnection.ConnectionString = System.Configuration.ConfigurationManager.AppSettings["a"].ToString(); //file upload path //string path = fileupload1.PostedFile.FileName; fileupload1.SaveAs(Server.MapPath("~/excel/" + fileupload1.FileName)); string a = "~/excel/" + fileupload1.FileName; //Create connection string to Excel work book string excelConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='a';Extended Properties=Excel 8.0 Xml;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 [ID],[Name],[Designation] from [Sheet1$]", excelConnection); excelConnection.Open(); OleDbDataReader dReader; dReader = cmd.ExecuteReader(); SqlBulkCopy sqlBulk = new SqlBulkCopy(strConnection); //Give your Destination table name sqlBulk.DestinationTableName = "Excel_table"; sqlBulk.WriteToServer(dReader); excelConnection.Close();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)