OleDbConnection cn = new OleDbConnection(……); cn.Open(); OleDbCommand cmd = new OleDbCommand("select username from table where (userpsw='"+userpsw.Text+"' and userid='"+userid.Text+"')",cn); cmd.ExecuteScalar(); if (cmd.ExecuteScalar() != null) { Response.Redirect("index.aspx"); } cn.Close();这里给出的是一份简单的代码.
cn.Open();
OleDbCommand cmd = new OleDbCommand("select username from table where (userpsw='"+userpsw.Text+"' and userid='"+userid.Text+"')",cn);
cmd.ExecuteScalar();
if (cmd.ExecuteScalar() != null)
{
Response.Redirect("index.aspx");
}
cn.Close();这里给出的是一份简单的代码.
{
MessageBox.Show("用户名不能为空!","注意",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
else if(txtpwd.Text.Trim()=="")
{
MessageBox.Show("密码不能为空!","注意",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
else
{
if(i<2)
{
string strcheck="select count(*) from userinfo where user=@Username and pwd=@Password";
OleDbCommand cmd=new OleDbCommand(strcheck,con);
cmd.Parameters.Add("@Username",System.Data.OleDb.OleDbType.VarChar,10);
cmd.Parameters.Add("@Password",System.Data.OleDb.OleDbType.VarChar,10);
cmd.Parameters["@Username"].Value=txtuser.Text.ToString().Trim();
cmd.Parameters["@Password"].Value=conn.Encrypt(txtpwd.Text.ToString().Trim());//加密
cmd.Connection.Open();
int n=(int)cmd.ExecuteScalar();
cmd.Connection.Close();
cmd.Dispose();
if(n!=0)
{
//登录成功
this.Close();
daybook InputForm =new daybook();//打开
InputForm.ShowDialog();
}
else
{
MessageBox.Show("登录失败!请重新输入!","失败",MessageBoxButtons.OK,MessageBoxIcon.Warning);
txtpwd.Text="";
txtpwd.Focus();
i++;
}
}
else
{
MessageBox.Show("已超过三次!系统退出!","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
this.Close();
}