protected void Button1_Click(object sender, EventArgs e) { try { string username = TextBox1.Text.Trim(); string pwd = TextBox2.Text.Trim(); if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(pwd)) { throw new Exception("请填写用户名密码"); } using ( CDBAccess cn = new CDBAccess(System.Configuration.ConfigurationSettings.AppSettings["OledbStr"])) { if (cn.HasRecord(@"select * from AdminUser where username=? and password=?", new OleDbParameter[] { new OleDbParameter("@usd", username), new OleDbParameter("@pwd", pwd) })) { UserLogin ul = new UserLogin(); ul.UserName = username; ul.PassWord = pwd; Session["UserLogin"] = ul; Response.Redirect("pages/classify.aspx"); } else { throw new Exception("密码不正确"); } } } catch (Exception ex) { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "test", "<script>layer.alert('" + ex.Message + "', 8);</script>"); } }