Example #1
0
        private List <Assets.Asset> DbToAsset(NpgsqlDataReader reader)
        {
            List <Assets.Asset> rtn = new List <Assets.Asset>();

            while (reader.Read())
            {
                Assets.Asset temp = new Assets.Asset();
                for (int i = 0; i < reader.GetColumnSchema().Count(); i++)
                {
                    helpers.SetPropValue(temp, reader.GetColumnSchema()[i].ColumnName, reader.GetValue(i).ToString());
                }
                rtn.Add(temp);
            }

            return(rtn);
        }
Example #2
0
        public Assets.Asset get_asset(NpgsqlConnection con, int id)
        {
            con.Open();

            Assets.Asset rtn = new Assets.Asset();

            using (var cmd = new NpgsqlCommand())
            {
                cmd.Connection  = con;
                cmd.CommandText = "SELECT * FROM assets where assets.\"Id\" = @id;";
                cmd.Parameters.AddWithValue("id", NpgsqlDbType.Integer, id);
                // cmd.Parameters.AddWithValue("id", id);

                using (var reader = cmd.ExecuteReader())
                {
                    rtn = DbToAsset(reader)[0];
                }
                con.Close();
                return(rtn);
            }
        }