Creating a StudentDB Class for ASP.NET 2.0 - Creating the Website and the App_Code Folder
(Page 2 of 5 )
Create a new ASP.NET website on the local file system and select Visual C# as the language. I will call the website TheSchool but you can call it whatever you like. You can accomplish this task from the menu option File ---> New ---> Web Site. Now we need to create the first class, which is the Student class. There is no data access code that will be written in that class. The Student class simply represents a row in the Students database table; the data access code will be written in the StudentDB class which has methods that accept instances of the Student class as a parameter and use this object to write a row to the database table. The best way to explain this is by example, so let's get to the code so you can understand what I mean. Don't worry though; we are going to talk more about this technique.
You can create a new C# Class Library Project for the Student class and reference it from your website, but there is an easier technique that you will prefer for small to medium websites. New in ASP.NET 2.0 is the "ASP.NET Folders" feature which provides special folders that are used in your website for special functionalities. For example the App_Code folder is used to store your C# utility classes, data access and business logic code files, like our C# Student.cs file that we are going to create.
The classes you add to this folder will be compiled into an assembly and referenced from your web site code so you can access it without adding a reference to it. You can also organize your files, inside the App_Code folder, into subfolders and write as many classes as your application needs. So let's add this special folder to our website. Right click on the web site entry at Solution Explorer, select Add ASP.NET Folder, and then click on App_Code as shown in the next screenshot:

Note that the App_Code folder has been added to the website's directory. Now right click on the App_Code folder, click on Add New Item, and then select a Class. Name this class Student.cs as shown in the next screenshot:

Let's write that class.
Next: Writing the Student class >>
More ASP.NET Articles
More By Michael Youssef