Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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:48am
Edited 17-Dec-12 2:55am
v3
Comments
CHill60 at 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 at 17-Dec-12 11:45am
   
Are you getting any error? What is your expected result and what is the actual?
Sergey Alexandrovich Kryukov at 17-Dec-12 14:29pm
   
Help with what? You did not ask question, did not explain any problem.
—SA

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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 at 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 at 18-Dec-12 0:11am
   
can you copy the the code if you added anything under the combo selection change event.??
Lakshmimsridhar at 18-Dec-12 0:13am
   
i didnt put selection change event.
jibesh at 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 at 18-Dec-12 0:21am
   
jibesh i done that. in new form i am getting but not getting here
jibesh at 18-Dec-12 0:24am
   
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 at 18-Dec-12 0:27am
   
just a second
Lakshmimsridhar at 18-Dec-12 0:39am
   
thanks for ur help. i solved it :)
jibesh at 18-Dec-12 0:40am
   
cool. btw. what was the problem ?
Lakshmimsridhar at 18-Dec-12 4:12am
   
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
0 Gihan Liyanage 332
1 Sergey Alexandrovich Kryukov 330
2 ClimerChinna 222
3 OriginalGriff 206
4 Richard MacCutchan 170
0 Sergey Alexandrovich Kryukov 8,298
1 OriginalGriff 7,112
2 CPallini 2,598
3 Richard MacCutchan 2,005
4 Abhinav S 1,788


Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 17 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100