首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

求教啊C#一直提示"未将对象引用设置到对象的实例"咋回事啊

2013-07-11 
求教啊,C#一直提示未将对象引用设置到对象的实例,怎么回事啊?这是错误截图下面是代码public ListCustom

求教啊,C#一直提示"未将对象引用设置到对象的实例",怎么回事啊?
这是错误截图
求教啊C#一直提示"未将对象引用设置到对象的实例"咋回事啊
下面是代码


public List<Customer> GetALL()
        {
            List<Customer> customers = new List<Customer>();
            customers=SqlHelper.ExcuteReader("select * from T_Customer");//就是在这里抛出异常的,可是SqlHelper是个静态类啊
            return customers;
        }

这是SqlHelper的

public static List<Customer> ExcuteReader(string str, params SqlParameter[] para)
        {
            using (SqlConnection sql = new SqlConnection(connection))
            {
                sql.Open();
                using (SqlCommand com = sql.CreateCommand())
                {
                    com.CommandText = str;
                    com.Parameters.AddRange(para);
                    using(SqlDataReader reader=com.ExecuteReader())
                    {
                        if (reader==null)
                        {
                            return null;
                        }
                        List<Customer> customers=new List<Customer>();


                        while (reader.Read())
                        {
                            Customer cus = new Customer();
                            cus.id = (long)reader["id"];
                            cus.name = (string)reader["name"];
                            cus.phonenummer = (string)reader["phonenummer"];
                            cus.address = (string)reader["address"];
                            cus.level = (int)reader["level"];
                            cus.birthday = (DateTime)reader["birthday"];
                            customers.Add(cus);
                        }
                        return customers;                 
                    }
                }
            }
        }


求大牛解答 C# 实例

SQL
[解决办法]
private static string connection = ConfigurationManager.ConnectionStrings["lianjie"].ConnectionString;
你看一下配置文件中有没有这个项,或者你直接改成
private static string connection = "你的连接字符串"
看一下,我估计应该是这里的问题

热点排行