ullas K

ullas K

  • NA
  • 55
  • 0

Updating those database records where datagridview checkbox rows is checked

Aug 14 2012 8:56 AM
I have a datagridview with the following columns in c#.net

1.checkboxcolumn
2.Issue Id
3.Book No
4.Book Name
5.Issue Date
6.Due Date
7.Remarks
8.Return Date


i have a textbox field named  Member no

 i have written code in text_leave event to fetch issue id, book no,book name,issuedate,due date
 and remarks from return table and fill the datagridview for the member no in textbox.

now what i need is to update the return table date field for rows where the checkbox field is checked.

For me only one row is updating.what is wrong

My code is:

DateTime returndt;
            int issueid;
            bool chk;
            for (int i = 0; i < dataGridViewEx1.Rows.Count-1; i++)

            {

                DataGridViewRow dr = dataGridViewEx1.Rows[i];
                returndt= DateTime.Parse(dr.Cells[7].Value.ToString());
                issueid=int.Parse(dr.Cells[1].Value.ToString());
                chk= ((bool)dr.Cells[0].Value);
               
                    if (chk == true)
                    {
                        try
                        {
                            con = db.open();
                            getdata = new SqlCommand("Update bookissue_return set returned_date='" + returndt.ToString("MM/dd/yyyy") + "',return_status='R' where issue_id=" + issueid + "", con);
                           getdata.ExecuteNonQuery();
                            db.close();


                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.ToString());
                        }

                        MessageBox.Show("Records Updated Successfully", "easyLib", MessageBoxButtons.OK);
                        this.Dispose();
                        this.Close();
                    }
             


            }

pls help and thanks in advance


Answers (4)