將datareader取出資料轉成Enum型態

2015年3月29日 星期日

(CreationStatus)Enum.Parse(typeof(CreationStatus), dataReader["CreationStatus"].ToString());

 
private static List AddECEventLog(IDataReader dataReader)
{
 var ecEventLogList = new List();
 while (dataReader.Read())
 {
  var ecEventLog = new ECEventLog();
  ecEventLog.ECEventId = dataReader["ECEventId"] == DBNull.Value ? null : dataReader["ECEventId"].ToString();
  ecEventLog.CreationStatus = (CreationStatus)Enum.Parse(typeof(CreationStatus), dataReader["CreationStatus"].ToString());
  ecEventLogList.Add(ecEventLog);
 }
 return ecEventLogList;
}

0 意見: