三层架构中 textBox显示数据库的内容 代码

 我来答
niwqiang
2012-05-11
知道答主
回答量:6
采纳率:0%
帮助的人:3.5万
展开全部
UI层:
public void SearchStu()
{
StudentInfo studentinfo = StuSyBLL.StuManageBLL.SearchStuInfo();
lblSex.Text = "男";
if (studentinfo.s_Sex != true)
{
lblSex.Text = "女";
}
lblName.Text = studentinfo.s_Name;
lblStuNum.Text = studentinfo.s_StuNo;
lblNation.Text = studentinfo.s_Nation;
lblIdCard.Text = studentinfo.s_IdCard;
lblCome.Text = studentinfo.s_Birthplace;
lblBeginTime.Text = studentinfo.s_EntranTime.ToString();
lblBirthday.Text = studentinfo.s_Brithday.ToString();

}
你把Label 改成textbox的就OK了

BLL层:
public static StudentInfo SearchStuInfo()
{
string strSql = string.Format("select * from [StudentManage].[dbo].[StudentInfo] where s_StuNo='v094926421123'");
return StuSyDAL.StuManageDAL.SearchStuInfo(strSql);
}

DAL层:
public static StudentInfo SearchStuInfo(string strSql)
{
StudentInfo studentinfo = new StudentInfo();

SqlDataReader dr = SQLHelper.ExecuteReader(strSql);
while (dr.Read())
{

studentinfo.c_ID = int.Parse(dr["c_ID"].ToString());
studentinfo.s_Name = dr["s_Name"].ToString();
studentinfo.s_StuNo = dr["s_StuNo"].ToString();
studentinfo.s_Sex = Convert.ToBoolean(dr["s_Sex"]);
studentinfo.s_Brithday =Convert.ToDateTime(dr["s_Brithday"]);
studentinfo.s_Birthplace = dr["s_Birthplace"].ToString();
studentinfo.s_IdCard = dr["s_IdCard"].ToString();
studentinfo.s_Nation = dr["s_Nation"].ToString();
studentinfo.s_EntranTime = Convert.ToDateTime(dr["s_EntranTime"]);

}
return studentinfo;
}
_只此一家
2012-05-11
知道答主
回答量:43
采纳率:0%
帮助的人:14.9万
展开全部
string MySql=“sql语句”
SqlCommand SqlCom = new SqlCommand(MySql, "数据库连接");
SqlDataReader dr = SqlCom.ExecuteReader();
if (dr.Read())
{
this.textBox.Text = dr["列名"].ToString();
}
dr.Close();
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式