Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="filename">excel文件完全限定路径</param>
        /// <param name="workTableName">excel文件工作表名称</param>
        /// <returns></returns>
        public DataSet GetData(string filename, string workTableName, out Exception exx)
        {
            DataSet         ds;
            string          strCon = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Extended Properties=Excel 8.0;" + "data source=" + filename;
            OleDbConnection myConn = new OleDbConnection(strCon);
            string          strCom = " SELECT * FROM [" + workTableName + "]";

            try
            {
                Open(myConn);//打开数据库
                OleDbDataAdapter myCommand = new OleDbDataAdapter(strCom, myConn);
                ds = new DataSet();
                myCommand.Fill(ds);
                myCommand.Dispose();
                exx = null;
                return(ds);
            }
            catch (Exception ex)
            {
                Errorlogdal dal = new Errorlogdal();
                dal.InsertErrorlog(new model.errorlog()
                {
                    errorSrc = "ExcelOperation->GetData", ErrorMsg = ex.Message, operation = 4
                });
                exx = ex;
                return(null);
            }
            finally
            {
                Close(myConn);
            }
        }
Example #2
0
 /// <summary>
 /// 根据条件获取异常信息
 /// </summary>
 /// <param name="error">搜索实体</param>
 /// <param name="skip">跳过多少条数据</param>
 /// <param name="take">去多少条数据</param>
 /// <returns></returns>
 public DataTable GetItaly(string ItalyCode, DateTime?createTime, DateTime?createTimeEnd, int skip, int take, out int pageRowsCount)
 {
     try
     {
         DataTable dt   = new DataTable();
         var       temp = from c in pbx.ItalyUpdateError select c;
         if (!string.IsNullOrWhiteSpace(ItalyCode))
         {
             temp = temp.Where(a => a.ItalyCode.Contains(ItalyCode));
         }
         if (createTime != null)
         {
             temp = temp.Where(a => a.createTime >= createTime);
         }
         if (createTimeEnd != null)
         {
             temp = temp.Where(a => a.createTime <= createTimeEnd);
         }
         pageRowsCount = temp.ToList().Count;
         temp          = temp.OrderByDescending(a => a.createTime).Skip(skip).Take(take);
         ItalyUpdateError stock = new ItalyUpdateError();
         List <string>    list  = new List <string>();
         foreach (var s in stock.GetType().GetProperties())
         {
             DataColumn cl = new DataColumn();
             cl.ColumnName = s.Name;
             list.Add(s.Name);
             // cl.DataType = s.GetType();
             dt.Columns.Add(cl);
         }
         foreach (ItalyUpdateError i in temp)
         {
             DataRow row = dt.NewRow();
             foreach (string s in list)
             {
                 //给row赋值
                 row[s] = i.GetType().GetProperty(s).GetValue(i);
             }
             dt.Rows.Add(row);
         }
         return(dt);
     }
     catch (Exception ex)
     {
         pageRowsCount = 0;
         Errorlogdal err = new Errorlogdal();
         err.InsertErrorlog(new errorlog()
         {
             operation = 3, errorTime = DateTime.Now, errorSrc = "ItalyErrordal->GetItaly()", ErrorMsg = ex.Source, errorMsgDetails = ex.Message
         });
         return(null);
     }
 }