public bool Login(string name, string pwd)
        {            SqlConnection con = new SqlConnection(str);            // string sql="select * from Users where Name= '";
            // sql+=name+"',Pwd= '"+pwd+"'";
            SqlCommand cmd = con.CreateCommand();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "CheckUser";
            cmd.Parameters.Add("@Name", SqlDbType.VarChar,50).Value="name";
            cmd.Parameters.Add("@Pwd", SqlDbType.Char, 10).Value = "pwd";
            con.Open();
            SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);//提示是这里有问题
            if (dr.Read())
            {
                con.Close();
                return true;
            }
            else
                con.Close();
            dr.Close();
            return false;
         }

解决方案 »

  1.   

                //                string sql="select * from Users where Name= '";
                //                sql+=name+"' and Pwd= '"+pwd+"'";
      

  2.   

    提示什么错误你先POST出来啊
    是不是没加Try Catch
      

  3.   

     SqlConnection myConnection = new SqlConnection();
                myConnection.ConnectionString = "Data Source=localhost;Integrated Security=SSPI;Initial Catalog=tms";
                SqlCommand myCommand = new SqlCommand("insert1", myConnection);
                myCommand.CommandType = CommandType.StoredProcedure;
                myConnection.Open();
               // DataSet ds = new DataSet();
                SqlParameter pan = new SqlParameter("@num", SqlDbType.Int, 100);
                pan.Value =int.Parse(textBox1.Text);
                myCommand.Parameters.Add(pan);
                try
                {
                    myCommand.ExecuteNonQuery();
                }
                catch (SqlException ex)
                {
                    MessageBox.Show("插入错误!" + ex.Message.ToString());
                }
                myCommand.Clone();
                myConnection.Close();
      

  4.   

    SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
    不是应该要用using的吗?
      

  5.   

    sqldatareader 已经关闭  不用using也搞的定的