0

I have a datagridview. Its first cell has a CheckBox column. I want to find the selected CheckBox row. "cells[0].value = null" always.

foreach (DataGridViewRow row in dataGridView1.Rows)
{

   if ((Convert.ToBoolean(row.Cells[0].Value) == true )) 
    {
        SqlCommand komut = new SqlCommand("insert into üreticiFirma (firma_ismi,konum,hammadde_isim,alıs_maliyeti,stok)values(@param2,@param3,@param4,@param5,@param6)", baglanti);

        komut.Parameters.AddWithValue("@param2", lblFirma.Text);
        komut.Parameters.AddWithValue("@param3", lblKonum.Text);
        komut.Parameters.AddWithValue("@param4", Convert.ToString(txtHammadde.Text));
        komut.Parameters.AddWithValue("@param5", Convert.ToInt32(row.Cells[7].Value));
        komut.Parameters.AddWithValue("@param6", txtMiktar.Text);
        komut.ExecuteNonQuery();
    }
}

andyrandy
  • 72,880
  • 8
  • 113
  • 130

1 Answers1

0
            baglanti.Open();
            SqlCommand komut = new SqlCommand("Select * from hammaddeler", 
                               baglanti);
            SqlDataAdapter ad = new SqlDataAdapter(komut);
            DataTable dt = new DataTable();
            ad.Fill(dt);
            dataGridView1.DataSource = dt;
            baglanti.Close();

            private System.Windows.Forms.DataGridView dataGridView1;
            private System.Windows.Forms.DataGridViewCheckBoxColumn Column1;