根据SQL数据库中的条目检查文本框

根据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. . .")
}