SqlCommand con = new SqlCommand(System.Configuration.ConfigurationSettings.AppSettings["sjk"]);
        con.Open();
        String sql="select id from user where name='"+this.TextBox1.Text+"'and password ='"+this.TextBox2.Text+"'";
        SqlCommand cmd =new SqlCommand (sql,con);
        SqlDataReader reader =cmd.ExecuteReader();
        if(readwr.Read()==true)
        {
           
            Response.Redirect("main.aspx");
           
        }
        else
        {
            Response.Redirect("login.aspx");
      
        }

解决方案 »

  1.   

    SqlConnection con = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["sjk"]); 
            con.Open(); 
            String sql="select id from user where name='"+this.TextBox1.Text+"'and password ='"+this.TextBox2.Text+"'"; 
            SqlCommand cmd =new SqlCommand (sql,con); 
            SqlDataReader reader =cmd.ExecuteReader(); 
            if(readwr.Read()==true) 
            { 
                
                Response.Redirect("main.aspx"); 
                
            } 
            else 
            { 
                Response.Redirect("login.aspx"); 
           
            }
      

  2.   

    SqlCommand当然没有open方法
    SqlConnection con = new SqlConnection (System.Configuration.ConfigurationSettings.AppSettings["sjk"]); 
      

  3.   


    SqlConnection con = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["sjk"]);
            //command对象是打开数据库后操作数据库的一个对象打开数据库用sqlconnection
            con.Open();
            String sql = "select id from [user] where name='" + this.TextBox1.Text + "'and password ='" + this.TextBox2.Text + "'";
            SqlCommand cmd = new SqlCommand(sql, con);
            SqlDataReader reader = cmd.ExecuteReader();
            if (reader.Read())
            {
                //数据库也不记得关闭,默认为true你何必手动写上??
                reader.Close();
                con.Close();
                Response.Redirect("main.aspx");        }
            else
            {
                Response.Redirect("login.aspx");
            }
      

  4.   


    using System;
    using System.Data;
    using System.Data.SqlClient;public class Test
    {
        static void ABC()
        {
            SqlConnection con = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["sjk"]);
            //command对象是打开数据库后操作数据库的一个对象打开数据库用sqlconnection
            con.Open();
            String sql = "select id from [user] where name='" + this.TextBox1.Text + "'and password ='" + this.TextBox2.Text + "'";
            SqlCommand cmd = new SqlCommand(sql, con);
            SqlDataReader reader = cmd.ExecuteReader();
            if (reader.Read())
            {
                //数据库也不记得关闭,默认为true你何必手动写上??
                reader.Close();
                con.Close();
                Response.Redirect("main.aspx");        }
            else
            {
                reader.Close();
                con.Close();
                //刚才忘记关闭了
                Response.Redirect("login.aspx");
               
            }
        }
    }
      

  5.   

    改过还有错误,
    异常详细信息: System.Data.SqlClient.SqlException: 在关键字 'user' 附近有语法错误。源错误: 
    行 25:         String sql="select * from user where name='"+this.TextBox1.Text+"'and password ='"+this.TextBox2.Text+"'";
    行 26:         SqlCommand cmd =new SqlCommand (sql,con);
    行 27:         SqlDataReader reader =cmd.ExecuteReader();
    行 28:         if(reader.Read()==true)
    行 29:         {