I have brought the data as below into the combobox. In my "BRANDS" table, the first column is brand_id and the second column is brand_name. I'm getting the names in the combobox, but I need to get the id's when saving it to the database. How can I do it ?
void markaekle() {
SqlCommand komut = new SqlCommand("Select * from MARKALAR", bgl.baglanti());
SqlDataReader dr = komut.ExecuteReader();
while (dr.Read())
{
comboBoxMarka.Properties.Items.Add(dr[1]);
}
bgl.baglanti().Close();
}
I need to save the id value to the database with a button like below:
private void BtnAnaGrupKaydet_Click(object sender, EventArgs e){
SqlCommand komut = new SqlCommand("INSERT INTO ANA_GRUP (marka_id,anagrup_isim,create_date) values (@p1,@p2,@p3)", bgl.baglanti());
komut.Parameters.AddWithValue("@p1", int.Parse(comboBoxMarka.Text));
komut.Parameters.AddWithValue("@p2", txtAnaGrup.Text);
komut.Parameters.AddWithValue("@p3", dateAnaGrup.DateTime);
komut.ExecuteNonQuery();
bgl.baglanti().Close();
MessageBox.Show("Ana Grup Sisteme Eklendi", "Bilgi", MessageBoxButtons.OK, MessageBoxIcon.Information);
}