我使用以下代码填充组合框。它显示:System.Data.DataRowView而不是其中的实际列值。我缺少什么?
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"];
答案 0 :(得分:2)
您可能需要设置DisplayMember和ValueMember属性:
cmbInstitutes.DisplayMember = "NameOfTheColumnForText";
cmbInstitutes.ValueMember = "NameOfTheColumnForValues";
或DataValueField和DataTextField如果它是ASP.NET应用程序。
答案 1 :(得分:1)
您可以使用以下代码在同一个组合框中填充两列。
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";