OK, its not complaining about accessing the DataSource property of the combobox, it complaining that the thing you are passing to Fill is typed as an object not a DataTable. Change your code to the following:
ComboBox cb = (ComboBox)sender; // you're assuming this to be the case so accept the exception if its not
DataTable dataSource = (DataTable)cb.DataSource;
odbcDA_CategoryLookUp.Fill(dataSource);
or more concisely
odbcDA_CategoryLookUp.Fill( (DataTable)((ComboBox)sender).DataSource );
although I think that is less readable ;-).
As for the relationship between the data adapter and the dataset, this is by design. The DataSet is a datasource independent cache of data. Data can de entered programatically (manually), by loading an XML document in or by using a DataAdapter.
Regards
Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk
This is good, but I'm not getting exactly what I'm after.
Here's what I'm trying to do:
ComboBox cb = sender as ComboBox;
odbcDA_CategoryLookUp.Fill(cb.DataSource);
I'm told (through a build error) that I can't convert from 'object' to
'System.Data.DataTable'.
This works, of course:
odbcDA_CategoryLookUp.Fill(dsCategoryLookUp);
It seems (intuitively) that I should be able to refer to one of the sender's
properties once I've cast it as the appropriate component type. I would
also like to be able to refer to the DataAdapter in the same manner, but
despite the fact that a specific DataAdapter was used to generate the
DataSet, I can't see any connection between them.
This is the way I see it presently. I'm really new to this environment, so
please correct any misconceptions. The ComboBox has a DataSource property,
but the DataSet pointed to therein doesn't specify the source of its own
data. The DataAdapter is used to stuff the DataSet specified by the
DataSource, but the objects that utilize these DataSets don't have a
property that specifies which DataAdapter should be used or is by default
associated with it.
Thanks.