I want to add a category for products in the program, when I click the add button, I get an error System.InvalidOperationException: 'The connection was not closed. Current state of the connection: open.' how can I solve it?
private void btnKategoriEkle_Click(object sender, EventArgs e)
{
kategorikontrol();
if (durum == true)
{
baglanti.Open();
SqlCommand komut = new SqlCommand("insert into kategoribilgileri(kategori) values('"+ txtKategori.Text+"')", baglanti);
komut.ExecuteNonQuery();
baglanti.Close();
MessageBox.Show("Kategori Eklendi");
}
else
{
MessageBox.Show("Böyle bir kategori var", "Uyarı");
}
txtKategori.Text = "";
}