winform combox绑定问题
在load事件里给两个combox绑定值,代码如下:
//combox1绑定值
ocnn = new OleDbConnection(connections);
ocnn.Open();
ocmd = ocnn.CreateCommand();
ocmd.CommandText = "select distinct Single_Date from MIS_InsertSingle";
DataSet ds = new DataSet();
oda = new OleDbDataAdapter(ocmd);
oda.Fill(ds);
this.cbo_Date.DataSource=ds.Tables[0];
ocnn.Close();
//combox2绑定值
OleDbConnection cnn = new OleDbConnection(connections);
cnn.Open();
OleDbCommand cmd = cnn.CreateCommand();
cmd.CommandText = "select Out_Date from MIS_OutSingle";
DataSet set = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
da.Fill(set);
this.cbo_OutDate.DataSource=set.Tables[0];
cnn.Close();
combox1显示正常而combox2的下拉列表值全是 System.Data.DataRowView。请问这是为什么。
------解决方案--------------------
------解决方案--------------------this.cbo_Date.DataSource=ds.Tables[0];
this.cbo_Date.DisplayMember = "显示字段";
this.cbo_Date.ValueMember = "ID(自增列或者编号)";
------解决方案--------------------楼上几位说的没错,楼主绑定数据源以后,设定一下DisplayMember ValueMember这两个属性就OK了