示例#1
0
        public void addGuardian(string c_fname, string c_lname, int phone)
        {
            guardian g = new guardian();

            g.fname = c_fname;
            g.lname = c_lname;
            g.phone = phone;

            string stmt = "INSERT INTO guardian(fname, lname, phone) VALUES (@c_fname, @c_lname, @phone)";

            using (var conn = new
                              NpgsqlConnection(ConfigurationManager.ConnectionStrings["Dbconn"].ConnectionString))
            {
                conn.Open();
                using (var cmd = new NpgsqlCommand(stmt, conn))
                {
                    cmd.Parameters.AddWithValue("c_fname", c_fname);
                    cmd.Parameters.AddWithValue("c_lname", c_lname);
                    cmd.Parameters.AddWithValue("phone", phone);
                    cmd.ExecuteNonQuery();
                }
            }
        }
示例#2
0
        public List <guardian> GetGuardian(Child child)
        {
            guardian        g;
            List <guardian> guardians = new List <guardian>();

            using (var conn = new
                              NpgsqlConnection(ConfigurationManager.ConnectionStrings["Dbconn"].ConnectionString))
            {
                conn.Open();
                using (var cmd = new NpgsqlCommand())
                {
                    cmd.Connection  = conn;
                    cmd.CommandText = "SELECT guardian.guardian_id, guardian.fname, guardian.phone, guardian.lname FROM guardian INNER JOIN guardian_child ON guardian_child.child_id = guardian.guardian_id WHERE guardian_child.child_id = @guardian_child.child_id ORDER BY guardian.lname ASC";
                    cmd.Parameters.AddWithValue("guardian_child.child_id", child.child_id);
                    using (var reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            g = new guardian();

                            g.guardian_id = reader.GetInt32(0);
                            g.fname       = reader.GetString(1);
                            if ((!reader.IsDBNull(2)))
                            {
                                g.phone = reader.GetInt32(2);
                            }
                            if ((!reader.IsDBNull(3)))
                            {
                                g.lname = reader.GetString(3);
                            }
                            guardians.Add(g);
                        }
                    }
                }
                return(guardians);
            }
        }