lundi 16 mars 2020

Why the value of datagridview checkbox not updated in the database windows application c#?

I have datagridview with DataGridViewCheckBoxColumn i want to update the database if checkbox checked update the test_status to 5 , if check box not checked keep the test_status = 4 . the column name initial result.

I used the following code when click SAVE button:

private void btnSave_Click(object sender, EventArgs e)
        {
             int test_status = 4;
            if (checkApproveResult.Checked == false && chkupdateApproved.Checked == false && chkReject.Checked == false)
            {
                txtUpdateCount.Text = "0";

                foreach (DataGridViewRow row in dgvResult.Rows)
                {
                  bool status = (bool)row.Cells[8].FormattedValue;
                    if (status)
                    {
                        test_status = 5;

                    }
                    else
                    {
                        test_status = 4;
                    }
                }

                    for (int i = 0; i < dgvResult.Rows.Count; i++)
                {
                    result.UPDATE_LABORDERS_RESULTS(Convert.ToInt32(txtOrder.Text),txtExamUser.Text,
                                              DateTime.Parse(DateTimeExamined.Value.ToString()),
                                              Convert.ToInt32(dgvResult.Rows[i].Cells[2].Value),
                                              dgvResult.Rows[i].Cells[4].Value.ToString(),
                                              dgvResult.Rows[i].Cells[5].Value.ToString(),
                                              Convert.ToInt32(dgvResult.Rows[i].Cells[7].Value.ToString()),
                                              Convert.ToInt32(txtPno.Text),
                                              Convert.ToInt32(txtcustid.Text),
                                              dgvResult.Rows[i].Cells[1].Value.ToString(),
                                              Convert.ToInt32(dgvResult.Rows[i].Cells[6].Value.ToString()),
                                              Convert.ToInt32(txtUpdateCount.Text),test_status);


                }

                MessageBox.Show("Result Saved Successfully ", "Entering Result", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
}

enter image description here

what is the wrong with my code , what i need to update ?




Aucun commentaire:

Enregistrer un commentaire