/// <summary> /// 从地磅系统里获取地磅表的数据 /// 使用返回的值之前先判断是否为null /// </summary> /// <param name="sql">查询语句</param> /// <returns>结果集</returns> EntityCollection GetEntityCollectionFromAccess(string sql) { EntityCollection entityCollection = null; string connectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;data source={0};", ConfigurationManager.AppSettings["dbConnectionString"]); using (OleDbConnection conn = new OleDbConnection(connectionString)) { conn.Open(); using (OleDbCommand cmd = conn.CreateCommand()) { cmd.CommandType = CommandType.Text; cmd.CommandText = sql; using (OleDbDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleResult)) { Wodeyun.Gf.Entities.PropertyCollection propertyCollection = new Wodeyun.Gf.Entities.PropertyCollection(); for (int i = 0; i < reader.FieldCount; i++) { propertyCollection.Add(new SimpleProperty(reader.GetName(i), reader.GetFieldType(i))); } entityCollection = new EntityCollection(propertyCollection); while (reader.Read()) { Entity entity = new Entity(propertyCollection); for (int i = 0; i < reader.FieldCount; i++) { entity.SetValue(i, reader.GetValue(i).ToVariable()); } entityCollection.Add(entity); } } } } return(entityCollection); }
public Entity(PropertyCollection propertyCollection, IList values) { this._PropertyCollection = propertyCollection; this._Values = values; }