职业IT人-IT人生活圈

 找回密码
 成为会员
搜索
查看: 2078|回复: 1

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

[复制链接]
娜娜乖乖女 发表于 2007-7-11 14:19 | 显示全部楼层 |阅读模式
是用来新手入门的,高手们不要见笑呀!
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(&#39;密码错误!&#39;)</script>\");
        }
      }
      else
      {
        Response.Write(\"<script>alert(&#39;用户名错误!&#39;)</script>\");
      }
    }
    else
    {
      Response.Write(\"<script>alert(&#39;用户不存在!&#39;)</script>\");
    }
  }
wei290 发表于 2008-1-9 15:37 | 显示全部楼层
额~我也是新手~

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

上面的 or 应该改成 and 吧
您需要登录后才可以回帖 登录 | 成为会员

本版积分规则

QQ|手机版|小黑屋|网站帮助|职业IT人-IT人生活圈 ( 粤ICP备12053935号-1 )|网站地图
本站文章版权归原发布者及原出处所有。内容为作者个人观点,并不代表本站赞同其观点和对其真实性负责,本站只提供参考并不构成任何投资及应用建议。本站是信息平台,网站上部分文章为转载,并不用于任何商业目的,我们已经尽可能的对作者和来源进行了通告,但是能力有限或疏忽造成漏登,请及时联系我们,我们将根据著作权人的要求立即更正或者删除有关内容。

GMT+8, 2024-5-9 12:48 , Processed in 0.142893 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表