ASP.NET一个最简单的会员登陆代码

王朝asp·作者佚名  2006-11-24
宽屏版  字体: |||超大  

是用来新手入门的,高手们不要见笑呀!

string conn = "server=.;database=login;user id=sa;pwd=123";

SqlConnection cn = new SqlConnection(conn);

cn.Open();

string strsql = "select user_name,user_pwd from admin where user_name='" + TextBox1.Text + "' or user_pwd='" + TextBox2.Text + "'";

SqlCommand cmd = new SqlCommand(strsql, cn);

SqlDataReader rd = cmd.ExecuteReader();

if (rd.Read())

{

if (rd.GetValue(0).ToString() == TextBox1.Text)

{

if (rd.GetValue(1).ToString() == TextBox2.Text)

{

Response.Redirect("Default.aspx");

}

else

{

Response.Write("<script>alert('密码错误!')</script>");

}

}

else

{

Response.Write("<script>alert('用户名错误!')</script>");

}

}

else

{

Response.Write("<script>alert('用户不存在!')</script>");

}

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有