if (FileUpload1.HasFile) { int aaa = FileUpload1.PostedFile.ContentLength; String savePath = (Server.MapPath("..\\Admin\\excel\\")); savePath += FileUpload1.FileName; FileUpload1.SaveAs(savePath); String conStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + savePath + ";Extended Properties=Excel 8.0"; OleDbConnection olcon = new OleDbConnection(conStr); olcon.Open(); OleDbCommand olcom = new OleDbCommand("SELECT Count(*) FROM [Sheet1$]", olcon); long count = Convert.ToInt32(olcom.ExecuteScalar()); Session["cou1"] = count; olcon.Close(); olcon.Open(); OleDbCommand olcom1 = new OleDbCommand("SELECT * FROM [Sheet1$]", olcon); OleDbDataReader dr; dr = olcom1.ExecuteReader(CommandBehavior.CloseConnection); DataTable dt = new DataTable(); dt.Load(dr); SqlConnection sqlConn = new SqlConnection(Con1); sqlConn.Open(); SqlBulkCopy bk = new SqlBulkCopy(sqlConn); bk.DestinationTableName = "Customer"; bk.WriteToServer(dt); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)