asp.net数据库问题
写了一个登录界面的登录按钮代码,但是总是有错,请大家指正一下,谢谢。代码如下:
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 = "";
}
}
运行后出现错误如下: