将来自sql server的数据显示为标签名称 [英] To display data from sql server into a label name

查看:66
本文介绍了将来自sql server的数据显示为标签名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以将sql server表中的数据显示到label.text中吗?
我正在填写注册表格,然后填写登录表格.
注册表单从文本框中获取值,对于安全性问题,我有一个组合框.因此,在注册和登录中,我已经成功完成了,但是我想更改用户密码,因此首先要在标签文本中显示安全性问题.我可以这样做吗?

[edit]已删除呼喊声-OriginalGriff [/edit]

Can I display data from from sql server table into a label.text?
I am making a registration form followed by a login form.
The registration form takes values from textboxes and for a security question I have a combo box. So in registration and login I have succeeded in that but I want to change the user password so I first want to display the security question into a label''s text. Can I do that?

[edit]SHOUTING removed - OriginalGriff[/edit]

推荐答案

确保您可以做到.
步骤:
1)创建连接对象
2)打开连接
3)创建sqlcommand通过传递选择查询来读取数据
4)执行阅读器
5)然后labelname.text = Reader ["Columnname"].ToString();


sure you can do that.
Steps:
1)Create connection object
2) open connection
3) create sqlcommand to read the data by passing the select query
4)execure reader
5) then labelname.text=Reader["Columnname"].ToString();


try
{
    SqlDataReader myReader = null;
    SqlCommand    myCommand = new SqlCommand("select * from table", 
                                             myConnection);
    myReader = myCommand.ExecuteReader();
    while(myReader.Read())
    {
        label.text=myReader["Column1"].ToString();

    }
}
catch (Exception e)
{
    messagebox.show(e.ToString());
}






您可以在
找到更多 通过C#访问SQL Server的入门指南 [ ^ ]






you can find more at
Beginners guide to accessing SQL Server through C#[^]


这篇关于将来自sql server的数据显示为标签名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆