int Num=0;
try{
this.System.Data.OleDb.OleDbConnection OleDBCon = new System.Data.OleDb.OleDbConnection();
this.OleDBCon.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\学生db1.mdb";
this.OleDbCommand OleDbComm = OleDbConn.CreateCommand();
OleDbComm.CommandText = "Select * from Login Where 学号='"+textBox1.text+"'and 密码='"+textBox2.text+"'";
this.OleDBCon.open();
this.System.Data.OleDb.OleDbDataReader OleDBDR = OleDbComm.ExecuteReader();
if(OleDBDR.Read())
{
this.OleDBCon.close();
Form2 MainFrm = new Form2();
this.hide();
MainFrm.ShowDialog();
}
else
{
Num+=1;
textBox1.Clear();
textBox2.Clear();
textBox1.Focus();
MessageBox.Show("学号或密码错误,请重新输入","Error");
}
if (Num >= 3)
{
MessageBox.Show("三次输入错误,程序退出","Error");
Application.Exit();
}
}
catch (Exception e)
{ MessageBox.Show(e.ToString()); }
[此贴子已经被作者于2006-11-29 19:56:29编辑过]