sda.Fill(dt)中的错误;

时间:2016-09-12 10:46:37

标签: mysql sql sql-server visual-studio visual-studio-2010

我在Visual Studio 10中创建了一个登录页面。每次运行程序时都会出现此错误:

enter image description here

这是我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;
    }
  }
}

1 个答案:

答案 0 :(得分:0)

你还没有打开连接。

con.Open();