2 swiftsunshine swiftsunshine 于 2013.12.23 20:08 提问

c# asp.net登录页面代码

作业,做一个简单的登录页面,与sql连接,但是总是出现错误,不能验证到已注册的用户,这里还没有写注册的代码,只是单纯的在已有账户中登录
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partial class login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void btnLogin_Click(object sender, EventArgs e)
{
    string uid = txtUid.Text;
    string pwd = txtPwd.Text;
    string conStr = "server=.;database=ShoppingDB;uid=sa;pwd=123456";
    string sql = "select * from Users where UserName ='{0}' and Password ='{1}'";
    sql = string.Format(sql, uid, pwd);
    SqlConnection conn = new SqlConnection(conStr);
    SqlCommand cmd = new SqlCommand(sql, conn);
    conn.Open();
    int res = cmd.ExecuteNonQuery();
    conn.Close();
    if (uid == null)
    {
        lab1.Text = "请输入用户名!!";
    }
    else if (res <= 0)
    {
        lab1.Text = "用户名不存在或密码错误!";
    }
    else
    {
        lab1.Text = "登录成功";

    }

}

}

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!