Click here to Skip to main content
15,917,795 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys. I am using Visual Studio 2008 to create a simple application. I have a single project called InventoryControlSystem. I wanted to make the code that accesses the database in a different class, so that my application will be 2-tier. I can add the a class to the project by right clicking on the project in Solution explorer.
But instead of adding the DataAccess class in the same namespace as the Windows Form class, I wanted to make it another namespace in the same project. The problem is I don't know how to it using VS 2008. It seems like one project is associated with one namespace.
Any ideas?

Thanks in advance
Posted

Just change the namespace at the top of your class declaration, e.g.

C#
namespace MyApplication
{
    public class MyClass
    {
    }
}


C#
namespace MyApplication.Data
{
    public class MyDataClass
    {
    }
}


Projects will have a 'default namespace' setting in the project properties that get applied to new items being added, you can always change from this though.

You probably want to put your data access code in a new assembly though and reference this from your winforms application.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 19-Apr-11 11:38am    
Correct. My 5.
In a way, name spaces are more stable than Assembly boundaries. There is nothing wrong with multiple name spaces per assembly; this is a very usual practice. Using default name space is not recommended.
--SA
Namespace naming guidelines is:

CompanyName.TechnologyName[.Feature][.Design]

For example:

HappyGoLucky.Database
HappyGoLucky.Media


In class file "DatabaseAccess.cs"
namespace HappyGoLucky.Database
{
  public class Access
  {
    public string Name
    {
      get
      {
        return "My name is Hans";
      }
    }
  }
}


And in your main program file "Program.cs"
namespace CoolProgram
{
  static class Program
  {
    static void Main()
    {
      HappyGoLucky.Database.Access d = new HappyGoLucky.Database.Access();

      Console.WriteLine("What is your name?");
      Console.WriteLine(d.Name);
      Console.ReadLine();
    }
  }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900