有个lable
想让他显示用户名
string s ="select name from User ";
SqlCommand com = new SqlCommand(s, conn);之后怎么把查询到的值传给LABLE?

解决方案 »

  1.   

    lable.Text = 查询到的值
      

  2.   

    qlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
                string str =="select name from User ";
                conn.Open();
    SqlCommand cmd = new SqlCommand(str, conn);
                try
                {
                    SqlDataReader sdr = cmd.ExecuteReader();
                    if (sdr.Read())
                    {
                        lable.Text= sdr["name"].ToString();
                    }               
                }
                catch(Exception e1)
                {
                    
                }
    conn.Close();
      

  3.   

    this.lable1.Text = 查询到的值