Esempio n. 1
0
        public AdresseModel GetHomeAdresse(int addressId)
        {
            SqlDataReader sqlDataReader = null;
            AdresseModel  adresseModel  = null;

            try
            {
                string     command = "select * from Adresse where AdresseId = #adresseId";
                SqlCommand cmd     = new SqlCommand(command.Replace("#adresseId", addressId.ToString()), conn);
                conn.Open();
                sqlDataReader = cmd.ExecuteReader();
                while (sqlDataReader.Read())
                {
                    adresseModel = new AdresseModel(
                        Convert.ToInt32(sqlDataReader["AdresseId"]),
                        sqlDataReader["Vejnavn"].ToString(),
                        Convert.ToInt32(sqlDataReader["HusNr"]),
                        Convert.ToInt32(sqlDataReader["PostNr"]),
                        sqlDataReader["Bynavn"].ToString(),
                        sqlDataReader["Type"].ToString());
                }
            }
            finally
            {
                if (sqlDataReader != null)
                {
                    sqlDataReader.Close();
                }
                if (conn != null)
                {
                    conn.Close();
                }
            }
            return(adresseModel);
        }
Esempio n. 2
0
        public List <AdresseModel> GetAllAdressesForPerson(int personId)
        {
            SqlDataReader       rdr        = null;
            List <AdresseModel> list       = new List <AdresseModel>();
            SqlConnection       secondConn = new SqlConnection(conn.ConnectionString); //nød til at have en ekstra, da conn bliver åbnet i getHomeAdress

            try
            {
                string cmdString = "select * from HarAdresse where (PersonId = #personId)";


                cmdString = cmdString.Replace("#personId", personId.ToString());

                SqlCommand cmd = new SqlCommand(cmdString, secondConn);

                secondConn.Open();
                rdr = cmd.ExecuteReader();
                while (rdr.Read())
                {
                    AdresseModel adresse = GetHomeAdresse(Convert.ToInt32(rdr["AdresseId"]));

                    list.Add(adresse);
                }
            }
            finally
            {
                if (rdr != null)
                {
                    rdr.Close();
                }
                if (conn != null)
                {
                    conn.Close();
                }
                if (secondConn != null)
                {
                    secondConn.Close();
                }
            }
            return(list);
        }
Esempio n. 3
0
        public List <AdresseModel> GetAdresses()
        {
            SqlDataReader       sqlDataReader = null;
            List <AdresseModel> list          = new List <AdresseModel>();

            try
            {
                SqlCommand cmd = new SqlCommand("select * from Adresse", conn);
                conn.Open();
                sqlDataReader = cmd.ExecuteReader();
                while (sqlDataReader.Read())
                {
                    AdresseModel adresse = new AdresseModel(
                        Convert.ToInt32(sqlDataReader["AdresseId"]),
                        sqlDataReader["Vejnavn"].ToString(),
                        Convert.ToInt32(sqlDataReader["HusNr"]),
                        Convert.ToInt32(sqlDataReader["PostNr"]),
                        sqlDataReader["Bynavn"].ToString(),
                        sqlDataReader["Type"].ToString());

                    list.Add(adresse);
                }
            }
            finally
            {
                if (sqlDataReader != null)
                {
                    sqlDataReader.Close();
                }
                if (conn != null)
                {
                    conn.Close();
                }
            }
            return(list);
        }