C#实现在sql查找数据显示在label控件上。
才开始学,不懂就问。
label.text = 你的变量名.ToString() 变量的值显示在标签上
如有帮助,望点击【本回答采纳】支持一下。
案例:
SqlConnection sqlconn = new SqlConnection();
sqlconn.ConnectionString = ;
sqlconn.Open();
SqlCommand cmd = sqlconn.CreateCommand();
cmd.CommandText = select 职务 from 用户信息 where 账号 = '7';
SqlDataReader reader = cmd.ExecuteReader();
reader.Read();
string temp_role = reader.GetString(0);
sqlconn.Close();
Label1.Text = temp_role;
查询出来把值设置给label就可以了,你是不知道连接数据库,查询数据,还是不知道把值绑定到控件呢?