主题:SOS!HELP!!用户信息验证的问题,请各位老大看一下
[em18]俺是初学者,有段关于用户验证的代码别人的可以但我粘贴过来都不能用.我也不知道是怎么回事,单步调了一下问题初步定在loginOK=true后应该执行public bool LoginOK{}但没有执行,还望各位老大不吝赐教.感激不尽!急用!代码部分如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication3
{
public partial class LoginForm : Form
{
private bool loginOK = false;
public bool LoginOK
{
get
{
return loginOK;
}
}
public LoginForm()
{
InitializeComponent();
}
private void LoginForm_Load(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“accessDataSet.User”中。您可以根据需要移动或移除它。
this.userTableAdapter.Fill(this.accessDataSet.User);
}
private void buttonLogin_Click(object sender, EventArgs e)
{
AccessDataSet.UserDataTable userTable = this.userTableAdapter.GetData();
string userName = this.textBoxUserName.Text;
string password = this.textBoxPassword.Text;
if ((userName != null) && (userName != ""))
{
if ((password != null) && (password != ""))
{
string queryString = "UserID = '" + userName
+ "' AND UserPassword = '" + password + "'";
DataRow[] users = userTable.Select(queryString);
if (users.Length > 0)
{
loginOK = true;
}
else
{
MessageBox.Show("无效的用户名或密码!");
}
}
else
{
MessageBox.Show("密码不能为空!");
}
}
else
{
MessageBox.Show("用户名不能为空!");
}
}
}
}
还有一部分代码但和问题无关.各位大虾帮帮忙啦.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication3
{
public partial class LoginForm : Form
{
private bool loginOK = false;
public bool LoginOK
{
get
{
return loginOK;
}
}
public LoginForm()
{
InitializeComponent();
}
private void LoginForm_Load(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“accessDataSet.User”中。您可以根据需要移动或移除它。
this.userTableAdapter.Fill(this.accessDataSet.User);
}
private void buttonLogin_Click(object sender, EventArgs e)
{
AccessDataSet.UserDataTable userTable = this.userTableAdapter.GetData();
string userName = this.textBoxUserName.Text;
string password = this.textBoxPassword.Text;
if ((userName != null) && (userName != ""))
{
if ((password != null) && (password != ""))
{
string queryString = "UserID = '" + userName
+ "' AND UserPassword = '" + password + "'";
DataRow[] users = userTable.Select(queryString);
if (users.Length > 0)
{
loginOK = true;
}
else
{
MessageBox.Show("无效的用户名或密码!");
}
}
else
{
MessageBox.Show("密码不能为空!");
}
}
else
{
MessageBox.Show("用户名不能为空!");
}
}
}
}
还有一部分代码但和问题无关.各位大虾帮帮忙啦.