日期:2014-05-18  浏览次数:20930 次

麻烦会的大神帮忙注释一下,新手不懂!!!!!
SqlConnection conn = new SqlConnection();//实例化对象
  string conStr = @"Data Source=WHIZENDT016\SQLEXPRESS;Initial Catalog=Users;Integrated Security=True";
  conn.ConnectionString = conStr;
  conn.Open();
  SqlCommand cmd = new SqlCommand("select * from Users_id where Id='" + textBox1.Text + "'and Password ='" + textBox2.Text + "'", conn);
  SqlDataReader str = cmd.ExecuteReader();
  str.Read();

------解决方案--------------------
C# code

           SqlConnection conn = new SqlConnection();//实例化对象
            //數據庫連接字符串
            string conStr = @"Data Source=WHIZENDT016\SQLEXPRESS;Initial Catalog=Users;Integrated Security=True";
            conn.ConnectionString = conStr;
            //打開連接
            conn.Open();
            //執行sql 命令
            SqlCommand cmd = new SqlCommand("select * from Users_id where Id='" + textBox1.Text + "'and Password ='" + textBox2.Text + "'", conn);
            //按READER方式執行查詢
            SqlDataReader str = cmd.ExecuteReader();
            //此次可循環READ,逐條取得結果
            str.Read();