public BookEntity GetBookByID(int id)
        {
            //BookEntity result = null;
            using (SqlConnection conn = this.CreateConnection())
            {
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "Select * from ebook_Book Where ID = @ID";
                    cmd.CommandType = CommandType.Text;
                    cmd.Parameters.Add("@ID", SqlDbType.Int);
                    cmd.Parameters["@ID"].Value = id;                    conn.Open();
                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            BookEntity entity = new BookEntity();  //"BookEntity"方法没有采用0个参数的重载
                            entity.ID = (int)reader["ID"];
                            entity.CategoryID = (int)reader["CategoryID"];
                            entity.Title = (string)reader["Title"];
                            entity.Description = (string)reader["Description"];
                            entity.Price = (decimal)reader["Price"];
                            entity.ImageUrl = (string)reader["ImageUrl"];
                            entity.OrderBy = (int)reader["OrderBy"];
                            return entity;
                        }
                    }                    conn.Close();
                }
            }
            return null;
        }为什么会发生 "BookEntity"方法没有采用0个参数的重载
而我在BookEntity中加入以下这句问题就解决了,为什麽啊?
 public BookEntity()
{
}
顺便问一下,有两本关于asp.net书《ASP.NET 2.0数据库入门经典(第4版)》(Wrox红皮书) 和《ASP.NET 2.0数据库入门经典(特别版)》有什么区别啊?? 

解决方案 »

  1.   

    这叫构造函数。oop课程缺课不少啊
      

  2.   

     public BookEntity() 


    缺少此构造函数的情况下
    当你的实体类被实例化的时候
    对象首先初始化构造函数
    BookEntity entity = new BookEntity();"new BookEntity();" 这一句是初始化你的类的构造函数但是现在又找不到该构造函数,所以抛出你那个异常
      

  3.   

    構造函數的問題 ,lz補補基礎吧《ASP.NET 2.0数据库入门经典(第4版)》(Wrox红皮书) 和《ASP.NET 2.0数据库入门经典(特别版)》特別版是后來推出的吧,都沒看過,不過感覺內容應該差不多
      

  4.   

    是不是定义了privite BookEntity()
    {}方法了?
      

  5.   

    呵呵,我是一个初学者,这些只是我照葫芦画瓢写的,这些不是构造函数吗?   
            public BookEntity(DataRow row)
            {
                ID = (int)row["ID"];
                CategoryID = (int)row["CategoryID"];
                Title = (string)row["Title"];
                Description = (string)row["Description"];
                Price = (decimal)row["Price"];
                ImageUrl = (string)row["ImageUrl"];
                OrderBy = (int)row["OrderBy"];
            
            }        public BookEntity(SqlDataReader row)
            {
                ID = (int)row["ID"];
                CategoryID = (int)row["CategoryID"];
                Title = (string)row["Title"];
                Description = (string)row["Description"];
                Price = (decimal)row["Price"];
                ImageUrl = (string)row["ImageUrl"];
                OrderBy = (int)row["OrderBy"];
            }
      

  6.   

    缺少
            public BookEntity() 
            { 
            }方法
      

  7.   

    这些后面都带着参数
    而你写的
    BookEntity entity = new BookEntity(); 
    为不带参数的
      

  8.   

    缺少 
            public BookEntity()  
            {  
            } 方法