String strCon = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + System.Windows.Forms.Application.StartupPath +"\\db2.mdb";
OleDbConnection myConn = new OleDbConnection(strCon);
try
{
myConn.Open();
}
catch (OleDbException ee)
{
MessageBox.Show(ee.Message);
}
string strSql =
"select count(*) from yonghu where 用户名='" + this.textBox1.Text + "'and 密码='" + this.textBox2.Text + "' ";
// MessageBox.Show(strSql);
OleDbCommand cmd = new OleDbCommand(strSql, myConn);
int count = Convert.ToInt32(cmd.ExecuteScalar());
if (count > 0)
{
Form2 child = new Form2();
child.Show();
this.Hide();
//MessageBox.Show("登录成功");
}
else
{
MessageBox.Show("用户帐号或密码错误!");
}
myConn.Close();