String filepath = Server.MapPath("UploadData"); FileUpload1.SaveAs(filepath + "\\" + FileUpload1.FileName.Split('\\')[FileUpload1.FileName.Split('\\').Length - 1]); string excelPath = (filepath + "\\" + FileUpload1.FileName.Split('\\')[FileUpload1.FileName.Split('\\').Length - 1]); string OledbConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + excelPath + ";Extended Properties=Excel 8.0;"; OleDbConnection cn = new OleDbConnection(OledbConnectionString); cn.Open(); try { string query = string.Format(" select * from [{0}]", "Sheet1$"); OleDbDataAdapter ad = new OleDbDataAdapter(query, cn); DataSet ds = new DataSet(); ad.Fill(ds, "Attendance"); DataTable dt = ds.Tables[0]; foreach (DataRow dr in dt.Rows) { string FName = dr[0].ToString(); string Lname = dr[1].ToString(); string Att = dr[2].ToString(); string QU = "insert into ABC values('" + FName + "','" + Lname + "','" + Att + "')"; SqlConnection cnp = new SqlConnection(bl.Cn); cnp.Open(); SqlCommand cmd = new SqlCommand(QU,cnp); cmd.ExecuteNonQuery(); cn.Close(); cnp.Close(); } Label1.Text = "ok"; } catch (Exception e) { cn.Close(); Label1.Text = e.Message; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)