Import Excel File in C#

  1. string filename = "roc\\" + DateTime.Now.ToString("ddMMyyyyhhMM_") + FileUpload1.FileName;  
  2.    FileUpload1.SaveAs(Server.MapPath(filename));  
  3.    lblmsg.Text = filename;  
  4. string connectionstring = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath(filename) + ";Excel 12.0 Xml;HDR=YES"// string connectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;" + // @"Data Source=" + Server.MapPath(filename) + ";" + //"Extended Properties=Excel 8.0;"; OleDbConnection con = new OleDbConnection(connectionstring); OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", con); DataTable dtt = new DataTable(); da.Fill(dtt);