方法一:
在winfron窗体中写入
//下拉框和数据库的实现
public static DataTable GetAreaDataTable()
{
string sqlStr = "select ENAME from A where EID ='1'";
DataTable dt = DAL.DBHelper.GetTable(sqlStr);
return dt;
}
public windows()
{
InitializeComponent();
//下拉框和数据库的实现
this.ComboBoxEdit1.Properties.NullText = "请选择...";
DataTable dt = GetAreaDataTable();
for (int i = 0; i < dt.Rows.Count; i++)
ComboBoxEdit1.Properties.Items.Add(dt.Rows[i]["ENAME "].ToString());
}
方法二:
UI层:
public windows()
{
InitializeComponent();
//下拉框和数据库的实现
this.ComboBoxEdit1.Properties.NullText = "请选择...";
DataTable dt = BLL.bll.Adapter();
for (int i = 0; i < dt.Rows.Count; i++)
ComboBoxEdit1.Properties.Items.Add(dt.Rows[i]["ENAME"].ToString());
}
BLL层:
public static DataTable Adapter()
{
return DAL.dal.Adapter();
}
DAL层:
public static DataTable Adapter()
{
string sqlcom = "select * from B where EID ='3'";
return DBHelper.GetTable(sqlcom);
}