Click here to Skip to main content
12,956,410 members (72,907 online)
Rate this:
 
Please Sign up or sign in to vote.
I save a "SalesReturn" object in my library which has few objects as property.

    namespace BusinessObjects
    {
    public class SalesReturn : ObjectBase
    {
 
        private Int32 pSalesReturnId;
        private SalesPerson pSalesPersonDetails=new SalesPerson();
        private PackSize pPackSizeDetails=new PackSize();
     
        public Int32 SalesReturnId
        {
            get { return pSalesReturnId; }
            set
            {
                if (!value.Equals(pSalesReturnId))
                {
                    pSalesReturnId = value;
                    PropertyHasChanged("SalesReturnId");
                }
            }
        }
 
        public SalesPerson SalesPersonDetails
        {
            get { return pSalesPersonDetails; }
            set
            {
                if (!value.Equals(pSalesPersonDetails))
                {
                    pSalesPersonDetails = value;
                    PropertyHasChanged("SalesPersonDetails");
                }
            }
        }
 
        public PackSize PackSizeDetails
        {
            get { return pPackSizeDetails; }
            set
            {
                if (!value.Equals(pPackSizeDetails))
                {
                    pPackSizeDetails = value;
                    PropertyHasChanged("PackSizeDetails");
                }
            }
        }
 
        public SalesReturn()
        {
        }
 
           
        public static SalesReturn FillEntity(SQLiteDataReader Reader,SQLiteConnection Connection)
        {
            SalesReturn salesreturn = new SalesReturn();
            salesreturn.pSalesReturnId = Convert.ToInt32(Reader["SalesReturnId"]);
            salesreturn.SalesPersonDetails =SalesPerson.GetEntity( Convert.ToInt32(Reader["SalesPersonId"]),Connection);
            salesreturn.pPackSizeDetails =PackSize.GetEntity( Convert.ToInt32(Reader["PackSizeId"]),Connection);
            salesreturn.MarkOld();
            return salesreturn;
        }
 
        public static SalesReturn GetEntity(int salesReturnId, string ConnectionString)
        {
            SalesReturn salesreturn = null;
            using (SQLiteConnection Connection = new SQLiteConnection(ConnectionString))
            {
                Connection.Open();
                string sqlSelect = "SELECT SalesReturnId, SalesPersonId, PackSizeId FROM tblSalesReturn WHERE SalesReturnId=" + salesReturnId + "";
                using (SQLiteCommand cmd = new SQLiteCommand(sqlSelect, Connection))
                {
                    SQLiteDataReader Reader = cmd.ExecuteReader();
                    if (Reader.HasRows)
                    {
                        Reader.Read();
                        salesreturn = FillEntity(Reader, Connection);
                    }
                    if (!Reader.IsClosed)
                    {
                        Reader.Close();
                    }
                }
                Connection.Close();
            }
            return salesreturn;
        }
 
    }
    }

I have a WinForm databound to this object. I am using a method to bind to that object.
        private void AddDataBindings()
        {
            bsSalesPerson.DataSource = SalesPerson.GetComboList(GlobalVariables.ConnectionString);
            cmbSalesPersonDetails.DataSource = bsSalesPerson;
            cmbSalesPersonDetails.ValueMember = "SalesPersonId";
            cmbSalesPersonDetails.DisplayMember = "FullNameInEnglish";
 
            bsPackSize.DataSource = PackSize.GetComboList(GlobalVariables.ConnectionString);
            cmbPackSizeDetails.DataSource = bsPackSize;
            cmbPackSizeDetails.ValueMember = "PackSizeId";
            cmbPackSizeDetails.DisplayMember = "ProductPackSize";
            lblUnitName.DataBindings.Add("Text", bsPackSize, "UnitName");
 
            bsCurrentEntity.DataSource = typeof(SalesReturn);
            cmbSalesPersonDetails.DataBindings.Add("SelectedItem", bsCurrentEntity, "SalesPersonDetails",false,DataSourceUpdateMode.OnPropertyChanged);
            cmbPackSizeDetails.DataBindings.Add("SelectedItem", bsCurrentEntity, "PackSizeDetails", false, DataSourceUpdateMode.OnPropertyChanged);
        }

My problem is when i retrieve an existing "SalesReturn" object from database, databound comboboxes are not showing the appropriate value.
private void LoadObject(object sender, EventArgs e)
{
        CurrentEntity = SalesReturn.GetEntity(salesReturnId, GlobalVariables.ConnectionString);
        bsCurrentEntity.DataSource = CurrentEntity;
}

I could not identify the problem. Would you please help me to identify it?
Posted 30-Jan-13 19:33pm

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,869
CHill60 3,550
Maciej Los 3,302
ppolymorphe 2,080
Jochen Arndt 1,973


Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 31 Jan 2013
Copyright © CodeProject, 1999-2017
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