tags:

views:

45

answers:

2

I use following code to populate a Combo Box. It displays: System.Data.DataRowView instead of the actual column values in it. What I am missing?

        string Query = "SELECT institutename FROM institutemaster";
        DataSet ds = new DataSet();
        MySqlDataAdapter da = new MySqlDataAdapter(Query, ConnectionClass.CN);
        da.Fill(ds, "Institutes");
        cmbInstitutes.DataSource = ds.Tables["Institutes"];
+2  A: 

You may need to set DisplayMember and ValueMember properties:

cmbInstitutes.DisplayMember = "NameOfTheColumnForText";
cmbInstitutes.ValueMember = "NameOfTheColumnForValues";

or DataValueField and DataTextField if it is an ASP.NET application.

Darin Dimitrov
Ok, and if I want to populate two columns in the same ComboBox, then how to do?
RPK
You add a calculated column: http://ondotnet.com/pub/a/dotnet/2003/05/26/datacolumn_expressions.html
Darin Dimitrov
+1  A: 

you can populate two columns in same combobox using following code.

string Query = "SELECT (institutename +', '+city) as Institute  FROM institutemaster";
 DataSet ds = new DataSet();   
 MySqlDataAdapter da = new MySqlDataAdapter(Query, ConnectionClass.CN);        
da.Fill(ds, "Institutes");    
cmbInstitutes.DataSource = ds.Tables["Institutes"];
cmbInstitutes.DisplayMember = "Institute";
cmbInstitutes.ValueMember = "Institute";
Pragnesh Patel