Click here to Skip to main content
Rate this: bad
good
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 20:33pm

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

  Print Answers RSS
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,127
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 31 Jan 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