c# .net 做CS 程序 combox如何读取数据库数据

搭建的三层UI,BLL,DAL ,如何在表示层的combox 要读取数据库表中的第二列。DAL中我返回的是一个查找出来的List, 那么在表示层如何处理让combox读取这List中所有数据条的第二列。

DAL:

public static IList<Type> GetAllType()
{
IList<Type> types=new List<Type>();
sql="select * from Type";
using(SqlDataReader date Reader=DBHelper.GetReader(sql))
{
while(dataReader.Read())
{
Type type=new Type();
type.typeID=Convert.ToString(dataReader["typeID"]);
type.typeName=Convet.ToString(dataReader["typeName"]);
types.Add(type);
}
}
return types;
}

表示层怎么做??

你好 你可以尝试下我这个方法。
你在表示层接收数据层查询到得数据。在表示层代码
comboBox1.DataSource = list; //给下拉框指定数据源,这里数据源就是刚才就收到得集合
comboBox1.DisplayMember = ""; //如果集合是从数据库中读取的时候,需要指定一个列给下拉框来显示,这里comboBox1.DisplayMember = "typeName";
comboBox1.ValueMember = ""; //这就是下拉框的value值了。这里你可以写 comboBox1.ValueMember = "typeID";

完毕。。有什么问题hi我
温馨提示:答案为网友推荐,仅供参考
第1个回答  2009-07-06
这样试试吧

this.comboBox1.DataSource = DAL.GetAllType();
this.comboBox1.DisplayMember = "TypeName";
this.comboBox1.ValueMember = "TypeID";本回答被提问者采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网