Click here to Skip to main content
Sign Up to vote bad
good
See more: C#WinForm
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
 
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 17 Dec '12 - 2:48
Edited 17 Dec '12 - 2:55

Comments
CHill60 - 17 Dec '12 - 11:18
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:45
Are you getting any error? What is your expected result and what is the actual?
Sergey Alexandrovich Kryukov - 17 Dec '12 - 14:29
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!
  Permalink  
Comments
Lakshmimsridhar - 18 Dec '12 - 0:06
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:11
can you copy the the code if you added anything under the combo selection change event.??
Lakshmimsridhar - 18 Dec '12 - 0:13
i didnt put selection change event.
jibesh - 18 Dec '12 - 0:17
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:21
jibesh i done that. in new form i am getting but not getting here
jibesh - 18 Dec '12 - 0:24
this is really interesting. I would like to see the whole form code then. if its okay to share i can review and get back to you. may be any in shared location?
Lakshmimsridhar - 18 Dec '12 - 0:27
just a second
Lakshmimsridhar - 18 Dec '12 - 0:39
thanks for ur help. i solved it :)
jibesh - 18 Dec '12 - 0:40
cool. btw. what was the problem ?
Lakshmimsridhar - 18 Dec '12 - 4:12
i have added in pageload cmbshiftdetails.text = "Select", this was the problem. i removed it. it was working fine

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 OriginalGriff 216
1 Sergey Alexandrovich Kryukov 169
2 Tadit Dash 154
3 Richard MacCutchan 145
4 Santhosh G_ 115
0 Sergey Alexandrovich Kryukov 10,338
1 OriginalGriff 7,965
2 CPallini 4,201
3 Rohan Leuva 3,522
4 Maciej Los 3,159


Advertise | Privacy | Mobile
Web02 | 2.6.130523.1 | Last Updated 17 Dec 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid