winfrom dev11中的ComboBoxEdit(下拉框)和数据库的绑定
方法一:
在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);
}
DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。
更多推荐
所有评论(0)