关于登陆中的验证问题
此程序中当验证用户名错误时,跳过了,小弟不才,不知道如何来验证,还有就是当我使用代码中注释掉的相对路径引用时,也会提示错误,不知道怎么办?希望高手们指教.本人初学C#,很想入门,如果小弟有幸认识各位,小疵视为上帝所宠
MyQQ:253530133,谢谢各位的回复!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace WindowsApplication1
{
public partial class MyTest : Form
{
public MyTest()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source=e:\\exam.mdb");
// OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source='" + Application.StartupPath + "'\\exam.mdb");
OleDbCommand comm = new OleDbCommand("select * from admin WHERE userid='"+this.textBox1.Text.Trim()+"'", conn);
conn.Open();
OleDbDataReader dr = comm.ExecuteReader();
while(dr!=null)
//if(dr.Read()!=null)
{
if(dr["userid"].ToString()==this.textBox1.Text.ToString())
//if (this.textBox1.Text.Equals(dr["userid"].ToString().Trim()))
{
if (dr["password"].ToString() == this.textBox2.Text.ToString())
//if (this.textBox2.Text.Equals(dr["password"].ToString().Trim()))
{
MessageBox.Show("你是合法用户");
}
else
{
MessageBox.Show("密码错误!");
this.textBox2.Focus();
this.textBox2.SelectAll();
}
}
else
{
MessageBox.Show("此用户不存在,是否注册!");
//this.textBox1.SelectAll();
}
}
conn.Close();
}
catch(Exception ee)
{
MessageBox.Show(AX.Message);
}
}
}
}