Пример #1
0
        public TelefonModel GetHomeTelefon(int personId)
        {
            SqlDataReader rdr = null;
            TelefonModel  phone;

            try
            {
                // Open connection
                conn.Open();

                string cmdString = "select * from TelefonNr where (PersonId = #personId) AND (Type = 'Hjem')";

                // Instantiate a new command
                SqlCommand cmd = new SqlCommand(cmdString.Replace("#personId", personId.ToString()), conn);

                // Send command
                rdr = cmd.ExecuteReader();

                rdr.Read();
                phone = new TelefonModel(
                    Convert.ToInt32(rdr["TelefonId"]),
                    rdr["Type"].ToString(),
                    rdr["Nummer"].ToString(),
                    Convert.ToInt32(rdr["PersonId"]));
            }
            finally
            {
                // Close connection
                rdr?.Close();
                conn?.Close();
            }

            return(phone);
        }
Пример #2
0
        public List <TelefonModel> GetTelefons(int personId)
        {
            SqlDataReader       rdr  = null;
            List <TelefonModel> list = new List <TelefonModel>();

            try
            {
                // Open connection
                conn.Open();

                string cmdString = "select * from TelefonNr where (PersonId = #personId)";

                // Instantiate a new command
                SqlCommand cmd = new SqlCommand(cmdString.Replace("#personId", personId.ToString()), conn);

                // Send command
                rdr = cmd.ExecuteReader();

                while (rdr.Read())
                {
                    TelefonModel phone = new TelefonModel(
                        Convert.ToInt32(rdr["TelefonId"]),
                        rdr["Type"].ToString(),
                        rdr["Nummer"].ToString(),
                        Convert.ToInt32(rdr["PersonId"]));

                    list.Add(phone);
                }
            }
            finally
            {
                // Close connection
                rdr?.Close();
                conn?.Close();
            }

            return(list);
        }