string excelFile = Server.MapPath("~/service/data.xlsx");
//string strConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + excelFile + ";Extended Properties=Excel 8.0;";
string strConn = @"Provider=Microsoft.Ace.OleDb.12.0;Data Source= " + excelFile + ";Extended Properties='Excel 12.0;HDR=No;IMEX=1'";
OleDbDataReader myDataReader = null;
OleDbConnection myOleDbConnection = new OleDbConnection(strConn);
OleDbCommand myOleDbCommand = new OleDbCommand("SELECT * FROM [table1$]", myOleDbConnection);
myOleDbConnection.Open();
myDataReader = myOleDbCommand.ExecuteReader();
try
{
ModeBiz biz = new ModeBiz();
Mode model = new Mode();
string name = string.Empty;
while (myDataReader.Read())
{
model = new Mode();
name = myDataReader.GetValue(4).ToString();
biz.Add(model);
}
}
#region Catch
catch (System.Threading.ThreadAbortException ex)
{
ViewBag.ErrMsg = ex.Message;
}
catch (Exception ex)
{
ViewBag.ErrMsg = ex.Message;
}
finally
{
myDataReader.Close();
myOleDbConnection.Close();
}
#endregion