我在Visual Studio 10中创建了一个登录页面。每次运行程序时都会出现此错误:
这是我css/Default.aspx.cs
的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class css_Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=login;Integrated Security=True;");
SqlDataAdapter sda=new SqlDataAdapter("Select count(*) From Log_Table Where UserName ='" + TextBox1.Text + "' and Password='" + TextBox2.Text + "'",con);
DataTable dt = new DataTable();
sda.Fill(dt);
if (dt.Rows[0][0].ToString() == "1")
{
Response.Redirect("Default2.aspx");
}
else
{
Label1.Visible = true;
}
}
}
答案 0 :(得分:0)
你还没有打开连接。
con.Open();