0

I am new to asp.net. when I am trying to create an object of the BookDAL class in AddBook.aspx page it doesn't work, and I get the error above, though I have added the reference and and namespace properly, any help please

enter image description here

This is my code

namespace DataAccessLayer.DALS.OLIBDAL
{
   public  class BookDAL
   {
       public int B_Id { get; set; }
       public string IDwithChar { get; set; }
       public int Category_Id { get; set; }
       public string Title { get; set; }
       public string ISBN { get; set; }
       public DateTime Published_Date { get; set; }
       public DateTime System_Date { get; set; }
       public string Language { get; set; }
       public string Edition { get; set; }
       public string Author { get; set; }
       public bool Featured { get; set; }
       public string Description { get; set; }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using DataAccessLayer;

public partial class OLIB_AddBook : System.Web.UI.Page
{
    BookDAL book = new BookDAL(); 

    protected void Page_Load(object sender, EventArgs e)
    {
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
    }
}

2 Answers 2

1

Namespace is:

DataAccessLayer.DALS.OLIBDAL

Not:

DataAccessLayer

So replace:

using DataAccessLayer;

with:

using DataAccessLayer.DALS.OLIBDAL;
0

The problem is that you're not referencing the namespace correctly. As the BookDAL is located inside DataAccessLayer.DALS.OLIBDAL but you're referencing only DataAccessLayer. So include the following namespace in OLIB_AddBook.aspx.cs page:

DataAccessLayer.DALS.OLIBDAL

Note ASP.Net assumes every folder as a namespace. When you include a parent namespace the classes inside the child namespace(s) will not be accessible until you include them in your working class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.