none
Typed DataSet - why are properties not being correctly populated? RRS feed

  • Question


  • Using a typed Dataset.

    From debugging I can see that each dataset.<table> is filled with the correct data (see ###)

    cmbxPayee DisplayMember, ValueMember and DataSource each show the expected values (see <---)

    cmbxCategory DisplayMember and ValueMember show expected values but DataSource shows null (see ***)
    which is presumably why when I get to the line $$$ I receive the message "Object reference not set
    to an instance of an object."

    Also all lsbxSubCat properties show null (see +++)

    Why is cmbxCategory.DataSource = null? And why are lsbxSubCat properties null?

     public partial class frmMain : Form
      {
            Expenditure dataSet = new Expenditure();

            public frmMain()
            {
                InitializeComponent();

                new ExpenditureTableAdapters.TransactionTableAdapter().Fill(dataSet.Transaction); ###
                new ExpenditureTableAdapters.PayeeTableAdapter().Fill(dataSet.Payee); ###
                new ExpenditureTableAdapters.CategoryTableAdapter().Fill(dataSet.Category); ###
                new ExpenditureTableAdapters.SubCategoryTableAdapter().Fill(dataSet.SubCategory); ###
            }
         
            private void frmMain_Load(object sender, EventArgs e)
            {
                cmbxPayee.DisplayMember = dataSet.Payee.P_NameColumn.ToString(); <---
                cmbxPayee.ValueMember = dataSet.Payee.P_IdColumn.ToString(); <---
                cmbxPayee.DataSource = dataSet.Payee; <---
           
                cmbxCategory.DisplayMember = dataSet.Category.C_DescriptionColumn.ToString();
                cmbxCategory.ValueMember = dataSet.Category.C_IdColumn.ToString();
                cmbxCategory.DataSource = dataSet.Category; ***
           
                lsbxSubCat.DisplayMember = dataSet.SubCategory.S_DescriptionColumn.ToString(); +++
                lsbxSubCat.ValueMember = dataSet.SubCategory.S_IdColumn.ToString(); +++
                lsbxSubCat.DataSource = dataSet.SubCategory; +++
            }

            private void cmbxPayee_SelectedValueChanged(object sender, EventArgs e)
            {
                string thePayeeId = cmbxPayee.SelectedValue.ToString();
                MessageBox.Show(thePayeeId);
            }

            private void cmbxCategory_SelectedValueChanged(object sender, EventArgs e)
            {
                string theCatId = cmbxCategory.SelectedValue.ToString(); $$$
                MessageBox.Show(theCatId);
            }


        }
    Friday, October 31, 2008 10:53 PM

All replies

  • Is there anybody out there who can help? It's bad enough trying to learn this stuff and getting error messages when you think you've done everything correctly.
    Sunday, November 2, 2008 8:39 PM
  • Ah, weel, it seems that changing the position of the DataSource lines has solved the problem. No idea why.
    Monday, November 3, 2008 12:35 AM