Click here to Skip to main content
15,919,500 members

Comments by James Dean (Top 3 by date)

James Dean 8-Jun-20 19:02pm View    
I managed to fix this by refreshing the ListView that has checkbox. The code is here,

con = new SqlConnect();
con.SqlQuery("Select * from DeductionInfo");
ListViewDed();
            //LvDeductions.Items.Clear();
con = new SqlConnect();
con.SqlQuery("Select Firstname, Lastname, Department, Position from EmpRecord inner join EmpRecord2 on EmpRecord.empID = EmpRecord2.empID where EmpRecord.empID = @id");

con.cmd.Parameters.AddWithValue("@id", lblEmpID.Text);
sdr = con.cmd.ExecuteReader();
if (sdr.Read())
            {
                lblEmployeeName.Text = sdr[1].ToString() + "," + " " + sdr[0].ToString();
                lblEmpDept.Text = sdr[2].ToString() + "," + " " + sdr[3].ToString();
            }



con = new SqlConnect();
con.SqlQuery("Select * from EmployeeDeduct where EmployeeeID = @empID");
            con.cmd.Parameters.AddWithValue("@empID", lblEmpID.Text);
            sda = new SqlDataAdapter(con.cmd);
            ds = new DataSet();
            sda.Fill(ds);
            con.cmd.Connection.Close();
            if (ds.Tables[0].Rows.Count > 0)
            {
                for (int g = 0; g < ds.Tables[0].Rows.Count; g++)
                {
                    con = new SqlConnect();
                    con.SqlQuery("Select * from DeductionInfo");
                    sda = new SqlDataAdapter(con.cmd);
                    DataSet ds2 = new DataSet();
                    sda.Fill(ds2);
                    con.cmd.Connection.Close();
                    if (ds2.Tables[0].Rows.Count > 0)
                    {
                        for (int j = 0; j < ds2.Tables[0].Rows.Count; j++)
                        {

                            if (ds.Tables[0].Rows[g].ItemArray[0].ToString() == ds2.Tables[0].Rows[j].ItemArray[6].ToString())
                            {

                                LvDeductions.Items[j].Checked = true;

                            }
                        }
                    }
                }
            }



I want to change this code,

LvDeductions.Items[j].Checked = true;



Into this,


  con = new SqlConnect();
con.SqlQuery("Select * from DeductionInfo where DeductID like @id");
con.cmd.Parameters.AddWithValue("@id", ds2.Tables[0].Rows[j].ItemArray[6].ToString()+"");


I tried using Wildcard like this

con.cmd.Parameters.AddWithValue("@id", ds2.Tables[0].Rows[j].ItemArray[6].ToString()+"%");


and still shows me one row instead of three. I change the % to _ and I got error There is no row at position 0.
James Dean 8-Jun-20 12:16pm View    
I have a question, i have this result from this code if(ds.Tables[0].Rows[g].ItemArray[0].ToString() == ds2.Tables[0].Rows[j].ItemArray[6].To String()). I want to convert this result ds2.Tables[0].Rows[j].ItemArray[6].To String()) into an array. Because I want them to put in Select SQL query using wildcard. I tried adding "%" it just gives me one row instead of three when I fired to ListView.
James Dean 8-Jun-20 11:23am View    
My Bad I removed the DeductionInfo out of for loop