Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
I fetched all the username in Combobox1 displaymember as username and Id as value member.
 
Now I enabled a groupbox having a textbox,3 combobox and update button when i select an item in Combobox1.considering the valuemember of combobox1 fetching particular user and trying to display those details in groupbox(textbox contains the username,3 combo boxes having department designation role details) .My Database table having foreign keys(deparment,designation and role).It returns only 3 combobox value members not the display memeber(Text).How can i link these tow so that upon selecteing username in Combobox1 the corresponding values should appear in textbox as well as 3 comboboxes.
 
here is my code:
 
private void cmbBoxUpdateEmployee_SelectedIndexChanged_1(object sender, EventArgs e)
    {
          changecmbBoxValue();
 
    }     panelupdateEmployee.Visible = true;
 

    public void changecmbBoxValue()
    {
 
        try
        {
            textBoxUpdateEmployee.Enabled = true;
            cmbBoxUpdateEmpRoleID.Enabled = true;
            cmbBoxUpdateEmpDepartment.Enabled = true;
            cmbBoxUpdateEmpDesignation.Enabled = true;
            dbobj.Open();
            DataSet ds = new DataSet();
            if (!string.IsNullOrEmpty(cmbBoxUpdateEmployee.SelectedValue.ToString()))
            {
                string cmd = "select Name,RoleId,DepartmentId,DesignationId from tblEmployee where Name='" + cmbBoxUpdateEmployee.SelectedValue+ "'";
 
      //I get system.Datarow conversion not done error.
                ds = dbobj.ExecuteDataset(cmd);
                if ((ds.Tables[0].Rows.Count) > 0)
                {
                textBoxUpdateEmployee.Text = Convert.ToString(ds.Tables[0].Rows[0]          [0].ToString());
              cmbBoxUpdateEmpRoleID.SelectedIndex = Convert.ToInt32(ds.Tables[0].Rows[0][1].ToString());
                    cmbBoxUpdateEmpDepartment.SelectedIndex = Convert.ToInt32(ds.Tables[0].Rows[0][2].ToString());
                    cmbBoxUpdateEmpDesignation.SelectedIndex = Convert.ToInt32(ds.Tables[0].Rows[0][3].ToString());
                    lblupdatedelete.Text = " Update Successfully";
                    EmployeeUpdateInfo();
                    textBoxUpdateEmployee.Clear();
                }
            }              
 
        }
        catch (Exception ex)
        {
            MessageBox.Show("Error!!" + ex.Message);
        }
        finally
        {
            dbobj.Close();
        }
 

    }
How can i achieve this? any idea.
Posted 4-Apr-13 9:29am
Edited 4-Apr-13 9:48am
v2

1 solution

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

Solution 1

Try to change:
textBoxUpdateEmployee.Text = Convert.ToString(ds.Tables[0].Rows[0]          [0].ToString());
cmbBoxUpdateEmpRoleID.SelectedIndex = Convert.ToInt32(ds.Tables[0].Rows[0][1].ToString());
cmbBoxUpdateEmpDepartment.SelectedIndex = Convert.ToInt32(ds.Tables[0].Rows[0][2].ToString());
cmbBoxUpdateEmpDesignation.SelectedIndex = Convert.ToInt32(ds.Tables[0].Rows[0][3].ToString());
with:
textBoxUpdateEmployee.Text = ds.Tables[0].Rows[0][0].ToString();
cmbBoxUpdateEmpRoleID.SelectedText = cmbBoxUpdateEmpRoleID.FindStringExact(ds.Tables[0].Rows[0][1].ToString());
cmbBoxUpdateEmpDepartment.SelectedText = cmbBoxUpdateEmpDepartment.FindStringExact(ds.Tables[0].Rows[0][2].ToString());
cmbBoxUpdateEmpDesignation.SelectedText = cmbBoxUpdateEmpDesignation.FindStringExact(ds.Tables[0].Rows[0][3].ToString());
 
Please, follow these links:
combobox.selectedtext[^]
combobox.FindStringExact[^]
combobox.FindString[^]
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 240
1 Kamal Rocks 184
2 CPallini 155
3 PIEBALDconsult 150
4 BillWoodruff 148
0 OriginalGriff 5,695
1 DamithSL 4,506
2 Maciej Los 4,007
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 6 Apr 2013
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