Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I save a "SalesReturn" object in my library which has few objects as property.

C#
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.
C#
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.
C#
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

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


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900