namespace Shoes.Data
{
    public class SqlHelper
    {
  
       private static int _queries = 0;
        private static string _connectionString = null;
        /// <summary>
        /// Parameters缓存哈希表
        /// </summary>
        private static Hashtable m_paramcache = Hashtable.Synchronized(new Hashtable());
        private static object lockHelper = new object();        /// <summary>
        /// 数据库连接字符串
        /// </summary>
        public static string ConnectionString
        {
            get
            {
                if (_connectionString == null)
                {
                    _connectionString = "Data Source=.;Initial Catalog=hpy123452009;Integrated Security=True";
                }
                return _connectionString;
            }
            set
            {
                _connectionString = value;
            }
        }      
        #region 私有方法
        /// <summary>
        /// 将SqlParameter参数数组(参数值)分配给SqlCommand命令.
        /// 这个方法将给任何一个参数分配DBNull.Value;
        /// 该操作将阻止默认值的使用.
        /// </summary>
        /// <param name="command">命令名</param>
        /// <param name="commandParameters">SqlParameters数组</param>
        private static void AttachParameters(SqlCommand command, SqlParameter[] commandParameters)
        {
            if (command == null) throw new ArgumentNullException("command");
            if (commandParameters != null)
            {
                foreach (SqlParameter p in commandParameters)
                {
                    if (p != null)
                    {
                        // 检查未分配值的输出参数,将其分配以DBNull.Value.
                        if ((p.Direction == ParameterDirection.InputOutput || p.Direction == ParameterDirection.Input) && (p.Value == null))
                        {
                            p.Value = DBNull.Value;
                        }
                        command.Parameters.Add(p);
                    }
                }
            }
        }
}
请问一下,为什么我无法调用到这里面的一些函数和方法?

解决方案 »

  1.   

    你是否引用了 Shoes.Data 命名空间或者相应的dll
      

  2.   

    一是 访问修饰符的问题 ,二 就是 命名空间  比如你想调用这个方法 Shoes.Data.SqlHelper.AttachParameters();自己检查检查  试试把public  替换private 
      

  3.   

    你是说为什么不能访问这个类中的私有静态方法吗?
    静态的只是说不要去new就能访问,但是你加了private(仅限本类内部访问,但是又加了个static,本类也不能访问),也就是外部内部再怎么折腾,始终不能访问该方法。
    建议把private改成public。
      

  4.   

     区分:private,空,protected,public 权限
      使用private修饰符可以完全隐藏类的成员,使得不能从类外直接访问它们。
      不使用修饰符允许同一个包里的任何类直接访问类的成员,但是其他包中的类不可以。
      使用protected修饰符允许任何包中的子类或同一包的类的成员。
      使用public修饰符允许任何类访问类的成员。
      

  5.   

    只有内部类才能访问你这中private static方法,如:   class Mouse
        {
            private static void test()
            {        }
            class newMouse
            {
                public void ss()
                {
                    test();
                }
            }
    }
      

  6.   

    不要都用static,我刚学的时候也是这样,变量和方法也喜欢用static,如果用static的话,调用时用类名.方法名  或者类名.变量 ,所以你上变的一些方法或者变量都不能调用。你还是把static去掉吧。
      

  7.   

    其实这个只要using Shoes.Data; 就可以了,如果要用层的话,那么久直接再写个引用就可以了,我昨天自己查阅了资料了