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?
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.
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
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