public CDataAccessBase[] getObjList(IDataAccessBase obj, int RecordCount) { CClassQuery ccq = obj.generateListSql(RecordCount); if (ccq == null) { return(null); } Type t = obj.GetType(); DataTable dt = this.ExecQuery(ccq.sql, ccq.parameters); CDataAccessBase[] ba = null; if (dt.Rows.Count > 0) { ba = new CDataAccessBase[dt.Rows.Count]; } int i = 0; foreach (DataRow dr in dt.Rows) { CDataAccessBase k = (CDataAccessBase)Activator.CreateInstance(t); k.InitFromDataRow(dr); ba[i] = k; i++; } return(ba); }
//从数据库中恢复对象 public void Db2Obj(CDataAccessBase obj, string PkValue) { string tableName = obj.TableName; using ( DataTable dt = ExecQuery("select * from " + tableName + " where " + obj.PKFieldName + "='" + (PkValue) + "' ")) { DataRow dr; if (dt.Rows.Count > 0) { dr = dt.Rows[0]; obj.InitFromDataRow(dr); } else { obj = null; } } }
public CDataAccessBase getObj(IDataAccessBase obj) { CClassQuery ccq = obj.CheckObj(); if (ccq == null) { return(null); } Type t = obj.GetType(); DataTable dt = this.ExecQuery(ccq.sql, ccq.parameters); CDataAccessBase ba = null; int i = 0; foreach (DataRow dr in dt.Rows) { CDataAccessBase k = (CDataAccessBase)Activator.CreateInstance(t); k.InitFromDataRow(dr); ba = k; break; } return(ba); }