Ashok Kumar

Ashok Kumar

  • NA
  • 38
  • 45.9k

error selecting listview value and displaying in textboxes

Aug 3 2012 1:49 AM
Hi friends,
        i am working a small application which should display data in textbox when selected the listview , the problem i am getting when i apply leaves for same employee code with differnt leave type and when i am selecting the recorded added listview to show data in textboxes it getting error and displaying the data but when i close the application and open and again i select the recorded from listview the error will not come for the first time applying and selected record for first time only it will come. please some one help me.

the error is
it will show  'fromdate ' in a small box, first time when i select listview index record, when i added leaves for same employee code different leave type

the code is

  private void listapproval_SelectedIndexChanged(object sender, EventArgs e)
        {
             try
            {
                groupBox3.Visible = true;
                txtEmpCode.Enabled = false;
                btnSave.Enabled = false;
                btnDelete.Enabled = true;
              //  btnDelete.Enabled = true;
                string empcode = "";
                string empname = "";
                string leavetype = "";
                string fromdate = "";
                string todate = "";
                string description = "";
                string status = "";
              

               
                for (int i = 0; i < listapproval.Items.Count; i++)
                {
                    if (listapproval.Items[i].Selected == true)
                    {
                        empcode = listapproval.Items[i].SubItems[0].Text;
                        empname = listapproval.Items[i].SubItems[1].Text;
                        leavetype = listapproval.Items[i].SubItems[2].Text;
                        fromdate = listapproval.Items[i].SubItems[3].Text;
                        todate = listapproval.Items[i].SubItems[4].Text;
                        status = listapproval.Items[i].SubItems[5].Text;
                        string q1="select LeaveCode From LeaveMaster Where LeaveName='"+leavetype+"'" ;
                            DBCom.getData(q1);
                        if(DBCom.rdr.HasRows)
                        {
                            while(DBCom.rdr.Read())
                            {
                                 lc =DBCom.rdr["LeaveCode"].ToString();

                            }
                        }




                        qry = "select * from LeavesApproval where EmployeeCode='" + empcode + "'and LeaveCode='"+lc+"'";
                        DBCom.getData(qry);
                        if (DBCom.rdr.HasRows)
                        {
                            while (DBCom.rdr.Read())
                            {
                                txtEmpCode.Text = DBCom.rdr["EmployeeCode"].ToString();
                                cmbLeave.Text = leavetype;
                                dtpFromDate.Text = DBCom.rdr["FromDate"].ToString();
                                dtpToDate.Text = DBCom.rdr["Todate"].ToString();
                                txtDescription.Text = DBCom.rdr["Description"].ToString();
                              
                               
                               
                            
                         }
                        }

                        qry = "select * from LeavesApproval where EmployeeCode='" + empcode + "'and LeaveCode='" + lc + "'";
                        DBCom.getData1(qry);
                        if (DBCom.rdr1.HasRows)
                        {
                            while (DBCom.rdr1.Read())
                            {
                                statuscode = Convert.ToInt32(DBCom.rdr1["Flag" ].ToString());
                            }
                        }

                        if (statuscode == 1)
                        {
                            status = "Pending";
                            rdbPending.Checked = true;
                        }
                        else if (statuscode == 2)
                        {
                            status = "Approved";
                            rdbApproved.Checked = true;
                        }
                        else if (statuscode == 3)
                        {
                            status = "Decline";
                            rdbDecline.Checked = true;
                        }
                        string q2 = "Select Leave_Balance From Employee_Leave where Emp_Code='" + empcode + "' and Leave_Code='" + lc + "'";
                        DBCom.getData(q2);
                        if (DBCom.rdr.HasRows)
                        {
                            while (DBCom.rdr.Read())
                            {
                                txtLeaveLeft.Text = DBCom.rdr["Leave_Balance"].ToString();
                            }
                        }


                    }
                }
           }