您好,登錄后才能下訂單哦!
/// <summary>
/// DataSet裝換為泛型集合
/// </summary>
/// <typeparam name="MoDeviceAbnormalStateRecord"></typeparam>
/// <param name="p_DataSet">DataSet</param>
/// <param name="p_TableIndex">待轉(zhuǎn)換數(shù)據(jù)表索引</param>
/// <returns></returns>
/// 2008-08-01 22:46 HPDV2806
public static List<MoDeviceAbnormalStateRecord> DataSetToIList(DataSet p_DataSet, int p_TableIndex)
{
if (p_DataSet == null || p_DataSet.Tables.Count < 0)
return null;
if (p_TableIndex > p_DataSet.Tables.Count - 1)
return null;
if (p_TableIndex < 0)
p_TableIndex = 0;
DataTable p_Data = p_DataSet.Tables[p_TableIndex];
// 返回值初始化
List<MoDeviceAbnormalStateRecord> result = new List<MoDeviceAbnormalStateRecord>();
for (int j = 0; j < p_Data.Rows.Count; j++)
{
MoDeviceAbnormalStateRecord _t = (MoDeviceAbnormalStateRecord)Activator.CreateInstance(typeof(MoDeviceAbnormalStateRecord));
PropertyInfo[] propertys = _t.GetType().GetProperties();
foreach (PropertyInfo pi in propertys)
{
for (int i = 0; i < p_Data.Columns.Count; i++)
{
// 屬性與字段名稱一致的進行賦值
MoDeviceAbnormalStateRecord Mo = new MoDeviceAbnormalStateRecord();
if (pi.Name.Equals(Mo.Datal2MO(p_Data.Columns[i].ColumnName)))
{
// 數(shù)據(jù)庫NULL值單獨處理
if (p_Data.Rows[j][i] != DBNull.Value)
pi.SetValue(_t, p_Data.Rows[j][i], null);
else
pi.SetValue(_t, null, null);
break;
}
}
}
result.Add(_t);
}
return result;
}
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。