Problem in DataGridView using c#
Hello every one,
Well in My DataGridView have Chekboxes which is Called From DB . i want to insert checkboxes selected values Data Base. and this is my code.
when i click the save button so on that time it is saved a lots of rows at one time click but i want that when i click save button only select one row if you have any idea then let me know...
try
{
con = new MySqlConnection("Server=localhost;user id =root;Password=.;DataBase=test");
con.Open();
foreach (DataGridViewRow dataGridRow in dataGridView1.Rows)
{
if (dataGridRow.Cells[0].Value != null &&
(bool)dataGridRow.Cells[0].Value)
{
cmd = new MySqlCommand("Insert into t_calculation values(" + dataGridView1.Rows[0].Cells[0].Value + "," + dataGridView1.Rows[0].Cells[1].Value + "," + dataGridView1.Rows[0].Cells[2].Value + "," + dataGridView1.Rows[0].Cells[3].Value + ")", con);
cmd.ExecuteNonQuery();
MessageBox.Show("Inserted");
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
}
thanks in Advance