SqlConnection con = new SqlConnection(/*connection string*/); FileUpload1.SaveAs(Server.MapPath("~//App_Data//") + FileUpload1.FileName); string path = Server.MapPath("~//App_Data//") + FileUpload1.FileName; try { //for .xls file System.Data.OleDb.OleDbConnection MyConnection; DataSet DtSet; System.Data.OleDb.OleDbDataAdapter MyCommand; MyConnection = new System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0; Data Source='" + path + "';Extended Properties=Excel 8.0;"); MyCommand = new System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection); DtSet = new System.Data.DataSet(); MyCommand.Fill(DtSet, "[Sheet1$]"); MyConnection.Close(); GridView1.DataSource = DtSet.Tables[0]; GridView1.DataBind(); SqlDataAdapter adpter = new SqlDataAdapter("Select * from StudentList", con); adpter.Update(DtSet.Tables[0]); Response.Write("successfully Imported values to SQL Server"); } catch (Exception ex) { Response.Write(ex.Message); }
SqlBulkCopy
con
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)