Winform Combobox için temiz bir ip ucu Select ekleme işlemi için
try
{
SqlCommand komut = new SqlCommand();
komut.CommandText = "SELECT * FROM Stok";
komut.Connection = baglanti;
komut.CommandType = CommandType.Text;
SqlDataReader dr;
baglanti.Open();
dr = komut.ExecuteReader();
urunCb.Items.Add(new DictionaryEntry("--SEÇİNİZ--", 0));
while (dr.Read())
{
urunCb.Items.Add(new DictionaryEntry(dr["Adi"], dr["Id"]));
}
urunCb.DisplayMember = "Key";
urunCb.ValueMember = "Value";
urunCb.DataSource = urunCb.Items;
baglanti.Close();
}
catch (Exception ex)
{
baglanti.Close();
MessageBox.Show("Stok ürün bilgileri çekilemedi. Hata " + ex);
}
