我有一个datagridview。它的第一个单元格具有一个CheckBox列。我想找到选定的CheckBox行。始终"cells[0].value = null"
。
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();
}
}
答案 0 :(得分: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;