本文介绍了如何检查用户是否在数据库中写入Sam表单Word的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此登录表格代码但不检查以后是否有资金

如何检查用户是否在数据库中写入Sam Word







SqlCommand myCommand = default(SqlCommand);



myCommand = new SqlCommand(SELECT用户名,PasswordUser FROM LoginTbl WHERE用户名= @Username和PasswordUser = @Password,myConnection);



SqlParameter uName = new SqlParameter(@ Username,SqlDbType.VarChar );

SqlParameter uPassword = new SqlParameter(@ Password,SqlDbType.VarChar);



uName.Value = txtUserName.Text;

uPassword.Value = txtPassword.Text;



myCommand.Parameters.Add(uName);

myCommand .Parameters.Add(uPassword);



myCommand.Connection.Open();



SqlDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);



if(myReader.Read()== true)

{

//MessageBox.Show(您已成功登录+ txtUserName.Text);

//隐藏登录表格

this.Hide();

FormMAIN2 fm = new FormMAIN2();

fm.ShowDialog();

Application.Exit ();

}





其他

{

MessageBox.Show(登录失败...再试一次!,登录拒绝,MessageBoxButtons.OK,MessageBoxIcon.Error);



txtUserName .Clear();

txtPassword.Clear();

txtUserName.Focus();



}

解决方案



This Code for Login Form But Not Check If The Later Capital Or Not
How Can Check If The User Write The Sam Word In Database



SqlCommand myCommand = default(SqlCommand);

myCommand = new SqlCommand("SELECT Username,PasswordUser FROM LoginTbl WHERE Username = @Username AND PasswordUser = @Password", myConnection);

SqlParameter uName = new SqlParameter("@Username", SqlDbType.VarChar);
SqlParameter uPassword = new SqlParameter("@Password", SqlDbType.VarChar);

uName.Value = txtUserName.Text;
uPassword.Value = txtPassword.Text;

myCommand.Parameters.Add(uName);
myCommand.Parameters.Add(uPassword);

myCommand.Connection.Open();

SqlDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);

if (myReader.Read() == true)
{
//MessageBox.Show("You have logged in successfully " + txtUserName.Text);
//Hide the login form
this.Hide();
FormMAIN2 fm = new FormMAIN2();
fm.ShowDialog();
Application.Exit();
}


else
{
MessageBox.Show("Login Failed...Try again !", "Login Denied", MessageBoxButtons.OK, MessageBoxIcon.Error);

txtUserName.Clear();
txtPassword.Clear();
txtUserName.Focus();

}

解决方案



这篇关于如何检查用户是否在数据库中写入Sam表单Word的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 12:07