using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; public partial class login : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } public SqlConnection GetConnection() { string myStr = "Data Source=.\\sqlexpress;Initial Catalog=mySQL;Integrated Security=True"; SqlConnection myConn = new SqlConnection(myStr); return myConn; } protected void enter_Click(object sender, EventArgs e) { SqlConnection myConn = GetConnection(); myConn.Open(); SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@number",SqlDbType.NVarChar ,50){Value =usernameTB .Text }, new SqlParameter ("@password",SqlDbType .NVarChar,50){Value =userpasswordTB .Text }, }; string sqlstr = "select * from userfome where usernumber=@number and userpassword=@password"; SqlCommand mycmd = new SqlCommand(sqlstr, myConn); mycmd.Parameters.AddRange(parameters); //SqlDataReader dr = mycmd.ExecuteReader(); if (mycmd.ExecuteScalar() != null) { Response.Redirect("~/聊天窗口/over.aspx"); } else { Response.Write("哈哈哈,登录失败了吧!"); } myConn.Close(); myConn.Open(); SqlDataReader rd = mycmd.ExecuteReader(CommandBehavior.CloseConnection); while (rd.Read()) { Application["Username"] = rd["username"]; Application["Usersex"] = rd["usersex"]; } myConn.Close(); } protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e) { } protected void lon_Click(object sender, EventArgs e) { goodjob(false); Response.Redirect("~/登录验证/login.aspx"); }
这 是 我写的登录页面的代码,我现在郁闷的就是,即使点注册,验证控件也会验证一下textbox里的内容是否为空。 我这里问题应该还会有,如果发现了,就指出来,我以后注意。