Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello
In my project am using a combobox to display all the fields from db( from different tables using view) .Here the problem is that For eg: Combobox name SID.SID contains two values 1 and 2.When we select the value: 1 it displays the Name filed,but when we change the selection to value: 2,the name field will not change .It remains the same.So how can i rectify this?


BAL Code for getting values from db
-----------------------------------

C#
public static DataTable GetAllDetails_Edit(int sid)
     {
         const string selectALL_ById = "exec[Select_By_Id_EditRegi]@SID";
         DAL.Method method = new DAL.SqlDataBase();
         method.SelectQuery(selectALL_ById);
         method.AddParameter("@SID", sid);

         DataTable cdTable = method.GetDataTable();
         method.Dispose();
         return cdTable;
     }


ComboBox IndexchangedCode
--------------------------

<pre lang="c#">private void cmbsid_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                if (cmbsid.Text.Trim() != "")
                {
                    pd.SID = Convert.ToInt32(cmbsid.SelectedValue);
                    DataTable dt = PersonelMethod.GetAllDetails_Edit(pd.SID);
                    if (dt.Rows.Count > 0)
                    {
                        txtFname.Text = dt.Rows[dt.Rows.Count - 1][1].ToString();

                    }
                }
            }
            catch (Exception ex)
            {
                CommonFunctions.Error(ex.ToString());
            }
        }


View Code
------------
SQL
<blockquote class="FQ"><div class="FQA">Quote:</div>ALTER PROCEDURE [dbo].[Select_By_Id_EditRegi]
@SID int
AS
BEGIN
SELECT     dbo.tbl_Personel.SID, dbo.tbl_Personel.FName, dbo.tbl_Personel.MName, dbo.tbl_Personel.LName, dbo.tbl_Personel.DOB, dbo.tbl_Personel.Sex, 
                      dbo.tbl_Personel.Age, dbo.tbl_Personel.Address, dbo.tbl_Personel.SponserName, dbo.tbl_Personel.EntryDate, dbo.tbl_others.SID AS Expr1, 
                      dbo.tbl_others.FamCond, dbo.tbl_others.FamNotes, dbo.tbl_others.Status, dbo.tbl_Family.FathName, dbo.tbl_Family.MothName, dbo.tbl_Family.Fam1, 
                      dbo.tbl_Family.Fam2, dbo.tbl_Family.Fam3, dbo.tbl_Family.Fam4, dbo.tbl_Family.Fam5, dbo.tbl_Family.Fam6, dbo.tbl_Family.Fam7, 
                      dbo.tbl_Family.Fam8, dbo.tbl_Family.SID AS Expr2
FROM         dbo.tbl_Family INNER JOIN
                      dbo.tbl_Personel ON dbo.tbl_Family.SID = dbo.tbl_Personel.SID INNER JOIN
                      dbo.tbl_others ON dbo.tbl_Personel.SID = dbo.tbl_others.SID

Where @SID=@SID
Posted
Comments
Alexander Dymshyts 8-Nov-13 3:36am    
Did you debug selectionIndexChanged?
Member 10370658 8-Nov-13 3:58am    
yes.Application is working fine ,but only one set of data will display at a time
BulletVictim 8-Nov-13 8:50am    
have you tried comboBox.ResetText()?
or else you can just setting the value to a null value before setting any values further down the way with each time the SelectedIndexChanged is called
Member 10370658 11-Nov-13 15:20pm    
Hello i have tried comboBox.ResetText().It works fine.

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