Click here to Skip to main content
15,897,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 2 combobox
one loads shift
second loads Department

on the click of a button i written query based on that query it should display result. but it only works for first values of two combobox not for others. what is the problem
please help me

C#
public void DisplayEmployee()
        {
            //try
            //{
                dtObj.Clear();
                flowLayoutPanel1.Controls.Clear();
                string s = CmbShiftdetails.Text;//.SelectedItem.ToString();
                string sql_displayemp = string.Format("SELECT EmployeeMaster.EmployeeId, EmployeeMaster.EmployeeCode, EmployeeMaster.EmployeeName, EmployeeMaster.Address, EmployeeMaster.PhoneNo, EmployeeMaster.Emailid, EmployeeMaster.Designation, EmployeeMaster.Photo, DepartmentMaster.DepartmentId, DepartmentMaster.DepartmentName, ShiftMaster.ShiftId, ShiftMaster.ShiftName FROM DepartmentMaster INNER JOIN EmployeeMaster ON DepartmentMaster.DepartmentId = EmployeeMaster.DepartmentId INNER JOIN ShiftMaster ON EmployeeMaster.ShiftId = ShiftMaster.ShiftId where ShiftMaster.ShiftName='{0}' and DepartmentMaster.DepartmentName='{1}'", CmbShiftdetails.Text, CmbDepartment.Text);
                
               
                
                dtObj = obj.NonTransaction(sql_displayemp);
                if (dtObj.Rows.Count > 0)
                {
                    TableLayoutPanel tlpobj = new TableLayoutPanel();
                    tlpobj.Name = "Emp";
                    tlpobj.CellBorderStyle = TableLayoutPanelCellBorderStyle.OutsetDouble;
                    tlpobj.AutoSize = true;

                    string[] headers = { "EmployeeCode", "EmployeeName", "Address", "PhoneNo", "Emailid", "Designation", "Photo", "Edit", "Delete" };
                    for (int i = 0; i < headers.Length; i++)
                    {
                        Label lbl = new Label();
                        lbl.Text = headers[i];
                        tlpobj.Controls.Add(lbl, i, 0);
                    }
                    for (int i = 0; i < dtObj.Rows.Count; i++)
                    {
                        Button btnedit = new Button();
                        btnedit.Text = "Edit";
                        btnedit.Name = "e_" + dtObj.Rows[i]["EmployeeId"].ToString();
                        btnedit.Click += new EventHandler(btnedit_Click);
                        btnedit.Width = 60;

                        Button btndelete = new Button();
                        btndelete.Text = "Delete";
                        btndelete.Name = "d_" + dtObj.Rows[i]["EmployeeId"].ToString();
                        btndelete.Click += new EventHandler(btndelete_Click);
                        btndelete.Width = 60;

                        Label lblempid = new Label();
                        lblempid.Text = dtObj.Rows[i]["EmployeeId"].ToString();
                        lblempid.Name = "lblempid" + dtObj.Rows[i]["EmployeeId"].ToString();
                        lblempid.Visible = false;

                        Label lblempcode = new Label();
                        lblempcode.Text = dtObj.Rows[i]["EmployeeCode"].ToString();
                        lblempcode.Name = "lblempcode" + dtObj.Rows[i]["EmployeeId"].ToString();

                        Label lblempname = new Label();
                        lblempname.Text = dtObj.Rows[i]["EmployeeName"].ToString();
                        lblempname.Name = "lblempname" + dtObj.Rows[i]["EmployeeId"].ToString();

                        Label lbladdress = new Label();
                        lbladdress.Text = dtObj.Rows[i]["Address"].ToString();
                        lbladdress.Name = "lbladdress" + dtObj.Rows[i]["EmployeeId"].ToString();

                        Label lblphone = new Label();
                        lblphone.Text = dtObj.Rows[i]["PhoneNo"].ToString();
                        lblphone.Name = "lblphone" + dtObj.Rows[i]["EmployeeId"].ToString();

                        Label lblemail = new Label();
                        lblemail.Text = dtObj.Rows[i]["Emailid"].ToString();
                        lblemail.Name = "lblemail" + dtObj.Rows[i]["EmployeeId"].ToString();

                        Label lbldesignation = new Label();
                        lbldesignation.Text = dtObj.Rows[i]["Designation"].ToString();
                        lbldesignation.Name = "lbldesignation" + dtObj.Rows[i]["EmployeeId"].ToString();

                        
                        

                        PictureBox pbemp = new PictureBox();
                        pbemp.SizeMode = PictureBoxSizeMode.StretchImage;
                        try
                        {
                            pbemp.Image = Image.FromStream(new MemoryStream(((byte[])dtObj.Rows[i]["Photo"])));
                        }
                        catch { }
                        pbemp.Name = "pbemp" + dtObj.Rows[i]["EmployeeId"].ToString();

                        ["EmployeeId"].ToString();

                       ["EmployeeId"].ToString();
                        // tlpobj.Controls.Add(lblempid, 0, i + 1);
                        tlpobj.Controls.Add(lblempcode, 0, i + 1);
                        tlpobj.Controls.Add(lblempname, 1, i + 1);
                        tlpobj.Controls.Add(lbladdress, 2, i + 1);
                        tlpobj.Controls.Add(lblphone, 3, i + 1);
                        tlpobj.Controls.Add(lblemail, 4, i + 1);
                        tlpobj.Controls.Add(lbldesignation, 5, i + 1);
                        //tlpobj.Controls.Add(lblemail, 4, i + 1);
                        tlpobj.Controls.Add(pbemp, 6, i + 1);
                        //tlpobj.Controls.Add(lbltagid, 6, i + 1);
                        // tlpobj.Controls.Add(lblshiftid, 7, i + 1);
                        tlpobj.Controls.Add(btnedit, 7, i + 1);
                        tlpobj.Controls.Add(btndelete, 8, i + 1);
                    }

                    flowLayoutPanel1.Controls.Add(tlpobj);
                    flowLayoutPanel1.Refresh();

                }
private void BtnGo_Click(object sender, EventArgs e)
        {
            DisplayEmployee();
        }
Posted
Updated 17-Dec-12 2:55am
v3
Comments
CHill60 17-Dec-12 11:18am    
If it works for some values and not for others I would suggest looking at your database - for example does that combination of shift and department actually exist in the database?
Kiran Susarla 17-Dec-12 11:45am    
Are you getting any error? What is your expected result and what is the actual?
Sergey Alexandrovich Kryukov 17-Dec-12 14:29pm    
Help with what? You did not ask question, did not explain any problem.
—SA

1 solution

1. Check the variable 'sql_displayemp' content i.e query string is updated with the second selection of the combo box controls
2. Check 'dtObj.Rows' returns any value for the above 'sql_displayemp'query, try copy the string content and execute in your SQL/database to ensure query is working correctly.
3.Put a break point at the line dtObj.Clear(); and you can able to solve yourself!
 
Share this answer
 
Comments
Lakshmimsridhar 18-Dec-12 0:06am    
i have done all those u did before itself. i am getting result for only for first selection. second selection input its not taking
Jibesh 18-Dec-12 0:11am    
can you copy the the code if you added anything under the combo selection change event.??
Lakshmimsridhar 18-Dec-12 0:13am    
i didnt put selection change event.
Jibesh 18-Dec-12 0:17am    
thats intresting... it should work. If you dont mind. can you create a new sample project and try the behavior of the combobox . just to make sure that we havent done anything unwanted.

This is what i used to do when i have some issue in native behavior of the control.
i mean: a new winform project with 2 combo and one button. check the .Text property of the combo inside ButtonClick event.
Lakshmimsridhar 18-Dec-12 0:21am    
jibesh i done that. in new form i am getting but not getting here

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900