asp,如何从数据库中读取一个数据并将其赋值给label控件
下面是我写的代码:{stringusername=Session["username"].ToString();SqlConnectionsqlconn=newSqlCo...
下面是我写的代码:
{
string username = Session["username"].ToString();
SqlConnection sqlconn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["connStr"].ConnectionString);
sqlconn.Open();
string sqlText = string.Format("SELECT Name FROM tb_User WHERE UserName ='{0}'", username);
SqlCommand sqlcmd = new SqlCommand(sqlText, sqlconn);
SqlDataReader dr = sqlcmd.ExecuteReader();
Labname.Text = dr.ToString();
sqlconn.Close();
}
为什么页面显示结果是这样 展开
{
string username = Session["username"].ToString();
SqlConnection sqlconn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["connStr"].ConnectionString);
sqlconn.Open();
string sqlText = string.Format("SELECT Name FROM tb_User WHERE UserName ='{0}'", username);
SqlCommand sqlcmd = new SqlCommand(sqlText, sqlconn);
SqlDataReader dr = sqlcmd.ExecuteReader();
Labname.Text = dr.ToString();
sqlconn.Close();
}
为什么页面显示结果是这样 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询