Main main=new Main();
if(loginname.Text!="" and password.Text!="")
{
string sqlstr1="select * from login where loginname="+loginname.Text+" and password="+password.Text+"";
OleDbConnection dbconn=new OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0;Data"+
" source="+Application.StartupPath+"\\90jxdb.mdb;Jet OLEDB:Database Password=123;Persist Security Info=False");
dbconn.Open();
OleDbCommand cmd=new OleDbCommand(sqlstr1,dbconn);
cmd.ExecuteNonQuery();
DataSet dataset=new DataSet();
OleDbDataAdapter oleda=new OleDbDataAdapter(sqlstr1,dbconn);
oleda.Fill(dataset);
if(dataset.Tables[0].Rows.Count!=0)
{
MessageBox.Show("登录成功!")
this.Close();
main.ShowDialog();
}
else
MessageBox.Show("用户名或者密码错误!")
}
else
{
MessageBox.Show("用户名或者密码不能为空!")
}
//Main是主窗体,上述代码写在登录按钮的点击事件里,登录页面上放两个文本框,分别是loginname,password,试试吧。