主要包含以下转换 :
- 使用DbDataReader填充对象.
- 使用DataSet填充对象.
- dataset转实体类
- 将实体类转换成DataTable
- 转换IList
为List - List
转换为ArrayList
///
///
System.Data.Common.DbDataReader reader) where T : new() { ArrayList resultList = new ArrayList(); Hashtable hashTable = fieldItem.DataValueToHashTable(); while (reader.Read()) { T emptyDataObject = new T(); for (int i = 0; i < reader.FieldCount; i++) { Object obj = reader.GetValue(i); if (hashTable[reader.GetName(i).ToString().ToUpper()] != null) { CommonHelper.Instance.SetProValue
ToString().ToUpper()].ToString(), obj); } } resultList.Add(emptyDataObject); } return resultList; } ///
///
///
DataSet dataset) where T : new() { ArrayList resultList = new ArrayList(); Hashtable hashTable = fieldItem.DataValueToHashTable(); foreach (DataRow dr in dataset.Tables[0].Rows) { T emptyDataObject = new T(); foreach (DataColumn dc in dr.Table.Columns) { if (hashTable[dc.ColumnName.ToUpper()] != null) { CommonHelper.Instance.SetProValue
hashTable[dc.ColumnName.ToUpper()].ToString(), dr[dc.ColumnName]); } } resultList.Add(emptyDataObject); } return resultList; } ///
///
///
///
DataItem fieldItem, System.Data.Common.DbDataReader reader) { ArrayList resultList = new ArrayList(); Hashtable hashTable = fieldItem.DataValueToHashTable(); while (reader.Read()) { object emptyDataObject = Activator.CreateInstance(typeEntity); for (int i = 0; i < reader.FieldCount; i++) { Object obj = reader.GetValue(i); if (hashTable[reader.GetName(i).ToString().ToUpper()] != null) { CommonHelper.Instance.SetProValue(typeEntity, emptyDataObject, hashTable[reader.GetName(i).ToString().
ToUpper()].ToString(), obj); } } resultList.Add(emptyDataObject); } return resultList; } ///
///
///
typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance); foreach (T t in objlist) { if (t == null) { continue; } row = dt.NewRow(); for (int i = 0, j = myPropertyInfo.Length; i < j; i++) { System.Reflection.PropertyInfo pi = myPropertyInfo[i]; string name = pi.Name; if (dt.Columns[name] == null) { column = new DataColumn(name, pi.PropertyType); dt.Columns.Add(column); } row[name] = pi.GetValue(t, null); } dt.Rows.Add(row); } return dt; } ///
///
///
最新评论