如何将数据库中查询出来的值赋给textbox?
展开全部
//估计还没有学三层 所以就用这个吧
string connstr=ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;//web.config里面去配
public SqlConnection GetConn()
{
return new SqlConnection(connstr);
}
public void BindData()
{
string id="";
string name = "";
using (SqlConnection c = GetConn())
{
string sqlString = "select id,name from xxx where id=5";
SqlCommand cmd = new SqlCommand(sqlString, c);
c.Open();
SqlDataReader r = cmd.ExecuteReader();
if (r.Read())//如果有多条就 while 那样绑定时候就得筛选了
{
//XClass x = new XClass();
id = r.GetString(0);
name = r.GetString(1);
}
}
this.tbxId = id;
this.tbxName = name;
}
string connstr=ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;//web.config里面去配
public SqlConnection GetConn()
{
return new SqlConnection(connstr);
}
public void BindData()
{
string id="";
string name = "";
using (SqlConnection c = GetConn())
{
string sqlString = "select id,name from xxx where id=5";
SqlCommand cmd = new SqlCommand(sqlString, c);
c.Open();
SqlDataReader r = cmd.ExecuteReader();
if (r.Read())//如果有多条就 while 那样绑定时候就得筛选了
{
//XClass x = new XClass();
id = r.GetString(0);
name = r.GetString(1);
}
}
this.tbxId = id;
this.tbxName = name;
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询