Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# datasource is returning System.Data.DataRowView

i have a combobox cbAnalytes:

cbAnalytes.DataSource = ConnectandReadList(qcvalues_query);

where the ConnectandReadList is:

public DataTable ConnectandReadList(string query)
{
    DataTable ds = new DataTable();
    string connection_string = "Data Source=hermes;database=qcvalues; Integrated Security=SSPI;";
    using (var myConnection = new SqlConnection(connection_string))
    {
        myConnection.Open();
        var command = new SqlCommand(query, myConnection);
        var adapter = new SqlDataAdapter(command);
        adapter.Fill(ds);
    }
    return ds;
}

for some reason it populates the combobox with:

System.Data.DataRowView
System.Data.DataRowView
System.Data.DataRowView
System.Data.DataRowView
System.Data.DataRowView

does anyone know what i am doing wrong?

like image 450
Alex Gordon Avatar asked Dec 04 '22 10:12

Alex Gordon


2 Answers

What are you setting your DisplayMember and ValueMember attributes to? You need to set those properties for your combobox in order for it to know what to display.

like image 193
AJ. Avatar answered Dec 14 '22 13:12

AJ.


For ASP.net:

cbAnalytes.DataValueField = "ColumnName";
cbAnalytes.DataTextField = "ColumnName";

For Windows Forms:

cbAnalytes.DisplayMember = "ColumnName";
cbAnalytes.ValueMember = "ColumnName"; // don't set this if you want the Value to be the DatRowView itself
like image 21
Dismissile Avatar answered Dec 14 '22 14:12

Dismissile