Im trying to populate a comboBox with the output of a query. What I get displayed in the comboBox is System.Data.DataRowView Here's the code that I use:
string subConStr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Master.accdb;Jet OLEDB:Database Password=password";
string query = "SELECT DISTINCT Code FROM MasterTable";
OleDbDataAdapter dAdapterComB = new OleDbDataAdapter(query, subConStr);
System.Data.DataTable source = new System.Data.DataTable() ;
dAdapterComB.Fill(source);
comboBoxSubject.DataSource = source;
comboBoxSubject.DisplayMember = "Subjects";
There is no column "Subjects" in your data table, so the combo box doesn't know which field to use to display the value in the combo box. When it can't find the member it just displays .ToString on thew DataRowView
You can try:
comboBoxSubject.DisplayMember = "Code";
Change the display member to "Code"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With