后台代码: protected void Button3_Click(object sender, EventArgs e)
    {
        string connstr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
        SqlConnection sconn = new SqlConnection(connstr);
        SqlCommand scmd = new SqlCommand();
        DataSet ds = new DataSet();        scmd.CommandText = "select*from Table1 where no='" + TextBox3.Text + "' and ps='" + TextBox4.Text + "'";        sconn.ConnectionString = connstr;
        scmd.Connection = sconn;
        sconn.Open();
        SqlDataReader dr = scmd.ExecuteReader();
    if (dr.Read())        { Response.Redirect("Default2.aspx"); }        else
        { Response.Redirect("Default3.aspx"); }    }
web.config
<connectionStrings>
<add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Login.MDF;Integrated Security=True;User Instance=True"/>
</connectionStrings>为什么点确定的时候没有反应?我是用windows身份登陆的,不用验证r .

解决方案 »

  1.   

    string connstr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
      SqlConnection sconn = new SqlConnection(connstr);
      
      string str = scmd.CommandText = "select * from Table1 where no='" + TextBox3.Text + "' and ps='" + TextBox4.Text + "'";try
    {
    sconn.open();
    SqlCommand scmd = new SqlCommand(str,sconn);
    object o = cmd.ExecuteScalar();
    if(o!=null)
    {
    登录成功
    }
    else
    {
    登录失败
    }
    }
    catch(Exception ex)
    {
    异常
    }
    finally
    {
    scoon.close();
    }
    不懂asp.net
    但是c#里这么写的话差不多了