asp.net1.0(C#)用户登录界面问题

来源:百度知道 编辑:UC知道 时间:2024/05/16 11:30:12
我是新手,请帮忙看看哪有出问题,谢谢,或许有什么更好的方法也帖出来
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.as

老大,你这个登录也太复杂了吧。
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;
}
}

另外注意命名的规范,数据库字段名最好不要用中文

记录当前登录的用户,可以用这个在做权限!!!

呵呵``你做的是有点复杂``顶楼上的``