我是新手,请帮忙看看哪有出问题,谢谢,或许有什么更好的方法也帖出来user是数据库的表,存入用户名和密码我的代码如下:private void Button1_Click(object sender, System.EventArgs e) { SqlConnection Conn=new SqlConnection("server=(local);database=student;uid=sa;pwd=''"); string selpwd="select 密码 from [user] where 用户名="+TextBox1.Text; string select="select * from [user]"; SqlCommand Comm=new SqlCommand(selpwd,Conn); SqlDataAdapter da=new SqlDataAdapter(select,Conn); Conn.Open(); DataSet ds=new DataSet(); da.Fill(ds,"grade"); DataView dv=new DataView(ds.Tables["grade"],"","用户名",DataViewRowState.CurrentRows); int rowindex=dv.Find(TextBox1.Text); if(rowindex!=-1) Label2.Text="该用户不存在或密码错误"; else { int pwd=(int)Comm.ExecuteScalar(); if(TextBox2.Text==pwd.ToString()) Response.Redirect("find.aspx"); else Label2.Text="该用户不存在或密码错误"; } Conn.Close();}还有session在登录界面起什么作用?
老大,你这个登录也太复杂了吧。private void Button1_Click(object sender, System.EventArgs e) {string userName = this.TextBox1.Text.toString();string userPwd = this.TextBox2.Text.toString();string strSql = "select * from student where userName ='" + userName + "' and userPwd ='" + userPwd + "'";SqlConnection Conn=new SqlConnection("server=(local);database=student;uid=sa;pwd=''"); Conn.open();SqlCommand cmd = new SqlCommand(strSql,Conn);int count = Convert.ToInt32(cmd.ExecuteScalar());if(login > 0){Session["admin"] = this.TextBox1.Text ;System.Web.Security.FormsAuthentication.RedirectFromLoginPage(this.TextBox1.Text,false);}else{this.lbLogin.Text= "用户名或密码不正确" ;this.lbLogin.Visible = true;}}另外注意命名的规范,数据库字段名最好不要用中文