コード例 #1
0
        public sehir sehirGetirId(int sehirId)
        {
            sehir s = new sehir();

            try
            {
                SqlCommand com = new SqlCommand("select * from Sehir where SehirId = @shrId  order by SehirAd", con);
                com.Parameters.AddWithValue("@shrId", sehirId);
                com.CommandType = CommandType.Text;

                con.Open();
                SqlDataReader dr = com.ExecuteReader();
                while (dr.Read())
                {
                    s.SehirId   = Convert.ToInt32(dr["SehirId"]);
                    s.SehirAd   = dr["SehirAd"].ToString();
                    s.PostaKodu = Convert.ToInt32(dr["PostaKodu"]);
                }
                dr.Close();
            }
            catch (Exception ex)
            {
            }
            finally
            {
                con.Close();
            }
            return(s);
        }
コード例 #2
0
        public List <sehir> sehirGetirTum()
        {
            List <sehir> sehirler = new List <sehir>();

            try
            {
                SqlCommand com = new SqlCommand("select * from Sehir  order by SehirAd", con);
                com.CommandType = CommandType.Text;

                con.Open();
                SqlDataReader dr = com.ExecuteReader();
                while (dr.Read())
                {
                    sehir s = new sehir();
                    s.SehirId   = Convert.ToInt32(dr["SehirId"]);
                    s.SehirAd   = dr["SehirAd"].ToString();
                    s.PostaKodu = Convert.ToInt32(dr["PostaKodu"]);
                    sehirler.Add(s);
                }
                dr.Close();
            }
            catch (Exception ex)
            {
            }
            finally
            {
                con.Close();
            }
            return(sehirler);
        }