注册 登录
编程论坛 ASP.NET技术论坛

asp.net数据库问题

powlin1991 发布于 2012-05-04 19:32, 718 次点击
写了一个登录界面的登录按钮代码,但是总是有错,请大家指正一下,谢谢。
代码如下:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

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

    }
    protected void Button1_Click(object sender, EventArgs e)
    {

            SqlConnection conn = new SqlConnection("server=.;database=user1;uid=sa;pwd=;");

            SqlCommand cmd = conn.CreateCommand();

            string sql = "select count(*) from user1 where 用户名='" + TextBox1.Text + "' and 密码='" + TextBox2.Text + "'";

             = sql;

            conn.Open();

            int count = (int)cmd.ExecuteScalar();

            if (count == 1)
            {
                Response.Redirect("./web/index.aspx");
            }
            else
            {
                Response.Write("<script>alert('你输入的用户名或密码错误!');</script>");
            }

            conn.Close();
        
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        Response.Redirect("login.aspx");
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        TextBox1.Text = "";
        TextBox2.Text = "";
    }
}

运行后出现错误如下:

只有本站会员才能查看附件,请 登录
6 回复
#2
powlin19912012-05-04 19:34
都是一些链接数据库之类的代码,但是不知道错误在哪里,麻烦指点一下是代码问题还是数据库我没设置正确(如果代码对的话应该就是数据库弄错了)
#3
cnfarer2012-05-05 14:59
设置sa密码!!!或者使用本地信任连接
#4
cjk_872012-05-07 09:14
powlin1991,我和你的问题是一样的,你那边怎么样喽!能指教一 下吗?我的Q:285151281,你呢?
#5
cjk_872012-05-07 09:15
版主,你能说的再祥细一点吗?我怀疑是数据库什么服务的事
#6
yekainew2012-05-23 19:16
应该是密码错误吧,密码是空的吗?
你先用企业管理器连接试下吧,

http://www.
#7
努力吼2013-03-08 15:02
你查询的是TextBox1.Text 的内容我觉得是 TextBox1.Text.Trim()
1