[请教高手]帮我看看代码那里有问题
using System;using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace MySchool
{
public partial class LoginForm : Form
{
public LoginForm()
{
InitializeComponent();
}
private void LoginForm_Load(object sender, EventArgs e)
{
loginType();
}
private void loginType()
{
DBHelper db = new DBHelper();
string selectSql = "select type from logintype";
SqlDataReader reader = db.QueryRs(selectSql);
while (reader.Read())
{
cboType.Items.Add(reader.GetString(0));
}
reader.Close();
db.Close();
}
public bool ValidateInput()
{
if (txtId.Text == string.Empty)
{
MessageBox.Show("请输入用户名","输入提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
txtId.Focus();
return false;
}
else if (txtPwd.Text == string.Empty)
{
MessageBox.Show("请输入密码","输入提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
txtPwd.Focus();
return false;
}
else if (cboType.Text == string.Empty)
{
MessageBox.Show("请选择登陆类型", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
cboType.Focus();
return false;
}
else
{
return true;
}
}
public bool ValidateUser(string loginId, string loginPwd, string loginType, ref string message)
{
DBHelper db = new DBHelper();
if (loginType == "学员")
{
string selectSql = string.Format("select count(*) from Student where loginId='{0}' and loginPwd='{1}'", loginId, loginPwd);
try
{
db.GetCon();
SqlCommand sqlCom = new SqlCommand(selectSql);
int num = (int)sqlCom.ExecuteScalar();
if (num > 0)
{
return true;
}
else
{
message = "用户名或密码不正确!";
return false;
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message.ToString());
return false;
}
finally
{
db.Close();
}
}
return false;
}
private void picLogin_Click(object sender, EventArgs e)
{
string message = "";
bool isValidateUser = false;
if (ValidateInput())
{
isValidateUser = ValidateUser(txtId.Text, txtPwd.Text, cboType.Text, ref message);
if (isValidateUser)
{
UserHelper.longinId = txtId.Text;
UserHelper.longinType = cboType.Text;
StudentForm stform = new StudentForm();
stform.Show();
this.Visible = false;
}
else
{
MessageBox.Show("登陆失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
private void picExit_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}
运行不报错无异常但是 不管我怎么修改 结果总是执行 不晓得那里的问题 (数据库里有数据)
else
{
MessageBox.Show("登陆失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}