根据SQL数据库中的条目检查文本框 [英] Check a textbox against an entry in a SQL Database

查看:85
本文介绍了根据SQL数据库中的条目检查文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



我用VB创建了一个简单的登录窗体。



目前所做的只是检查文本框中输入的内容是否正确,然后登录。



我现在正试图不设置一个值,并实际获取登录页面以检查SQL数据库中的许多用户名和密码。



任何建议表示赞赏。



问候,



Glen。

Hello,

Ive created a simple login windows form using VB.

At the moment all it does is checks what is entered into the text box against a set value if it is correct then login.

I am now trying not to have a set value and to actually get the login page to check against a number of usernames and passwords in a SQL database.

Any suggestions are appreciated.

Regards,

Glen.

推荐答案

考虑以下示例:

假设我有表tbleUserAuthentication,并且此表中有两列,即用户名和密码。

以下代码段将帮助您检查在文本框中针对SQL Server输入的信息。

Consider the following example:
Suppose i have table tbleUserAuthentication, and two columns in this table i.e, Username and Password.
Following piece of code will help you to check information entered in Textbox against SQL Server.
SqlConnection con = new SqlConnection("Your Connection Here");
SqlCommand cmd_retrvefrmDB = new SqlCommand("select * from tbleUserAuthentication where username=@u and Password=@p",con);
cmd_retrvefrmDB.Parameters.AddWithValue("@u",Your_UserName_TextBox.Text);
cmd_retrvefrmDB.Parameters.AddWithValue("@p",Your_UserPassword_TextBox.Text);
con.Open();
SqlDataReader dr = cmd_retrvefrmDB.ExecuteReader();
if (dr.Read())
{
         MessageBox.Show("User Logined. . .")
}
else
{
         MessageBox.Show("Invalid Username and Password. . .")
}


这篇关于根据SQL数据库中的条目检查文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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