"Windows窗体-Visual Studio" -C#中的登录表单 [英] Login Form in ""windows Form-Visual Studio"-C#

查看:74
本文介绍了"Windows窗体-Visual Studio" -C#中的登录表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生您好,
我正在Visual Studio中使用窗口表单."

我给了我两个标签(用户名和密码),其中有一个信息框和一个登录按钮.我在MS SQL中创建了一个用户名和密码字段,在该字段中给了用户名和密码值. .当我执行该命令时,将要求输入用户名和密码,当我输入该用户名和密码时,会出现类似在期望条件的上下文中在名称"附近指定了非布尔类型的表达式"之类的错误. .此行中的错误" SqlDataReader rdr = cmd.ExecuteReader();.任何人都可以解决此问题...

如果解决方案采用代码形式,则将对您有所帮助.

谢谢&问候
Pradeep

Hello sir,
"I am using window form in Visual Studio."

I had given two labels(username and password) with infornt of that ,there will be a textbox and one Login button.I created a username and password fields in MS SQL ,i had given value for username and password in the fields..ok.and when i execute that ,it will ask to enter the username and password,when i entered it will give a error like "An expression of non-boolean type specified in a context where a condition is expected, near ''Name'' ".The error in this line "SqlDataReader rdr = cmd.ExecuteReader();".Can any one solve this...

If solution in the code form ,then it will be helpfull.

Thanks & Regards
Pradeep

推荐答案

尝试一下:
Try this:
using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    using (SqlCommand com = new SqlCommand("SELECT iD, password FROM myTable WHERE userName=@UN", con))
        {
        con.Parameters.AddWithValue("@UN", userNameTextBox.Text);
        using (SqlDataReader reader = com.ExecuteReader())
            {
            if (reader.Read())
                {
                int id = (int) reader["iD"];
                byte[] pw = (byte[]) reader["password"];
                ...
                }
            }
        }
    }

然后您可以检查您的密码是否匹配,如果可以,请登录.
顺便说一句:不要以文本格式存储密码-这是一个真正的安全漏洞.而是使用哈希函数. 密码存储:操作方法. [

You can then check your password matches and log him in if it does.
BTW: Don''t store your password in text format - it is a real security hole. Instead, use a Hashing function. Password Storage: How to do it.[^]


检查您的SQL语句. if语句或其中的where子句有问题.
Check your SQL statements. There is something wrong with if statement or a where clause in it.


在此处粘贴您的代码...我们将尝试解决您的问题....
paste your code here...we will try to solve your problem....


这篇关于"Windows窗体-Visual Studio" -C#中的登录表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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