I have a problem with binding data using BindingSource, typed dataset and DataGridView. My problem is: BindingSource, therefore grid, is empty after binding data (bindingSource.Count is 0). I couldn’t figure out what I’m doing wrong and I’d be very happy if anyone could help me with this. My application structure is like this: I have two assemblies, one is Winforms UI and other is database class library.
UI
- DataGridView, datasource as BindingSource
- BindingSource, datasource = DBAssembly.typedDataset, datamember = DBAssembly.typedDataset.myTable
Database assembly
- Sql Server CE database
- Typed Dataset
- DB class for database operations
UI Code
OnLoad
this.db = new DB(); db.BindData();
DB Code
constructor
create typedDataSet object create typedDataSetTableAdapters.MyTableTableAdapter object create typedDataSetTableAdapters.TableAdapterManager object
BindData()
this.myTableTableAdapter.Fill(this.typedDataSet.MyTable)
I’d appreciate any help with this.
Well, the first thing to ask would be: what is
this.typedDataSet.MyTable.Rows.Count? i.e. did the adapter do anything? If not, it has nothing to do with the binding.Assuming it is non-empty, then what exact code are you using to set up
DataSourceandDataMember? I expect it should be:Alternatively, you could set the
bindingSource‘s DataSource tothis.typedDataSet.MyTableand leave the table blank.Basically, I expect that you’ve told it the type of data to anticipate, but so far you haven’t actually given it the data-set/data-table you want to use.