ASP.NET • Build an ASP.NET 2.0 Component

Listing 2. Start building a component or class in ASP.NET 2.0 by creating a folder named "Code" and placing all your components in that folder. Once the components are inside the Code folder, they'll be referenced automatically and made available to all the pages in your Web app. This example creates a Customers class and places that in the Code folder.

using System;
using System.Data.SqlClient;
using System.Data.Sql;
public class Customers
{
   public Customers()
   {         
   }
      public SqlDataReader GetCustomers()
      {
         SqlConnection sqlConn = new  
		    SqlConnection("server=
         localhost;uid=sa;pwd=thiru;
         database=northwind");
         sqlConn.Open();
         SqlCommand sqlCmd = 
         sqlConn.CreateCommand();
         sqlCmd.CommandText = "Select 
         CompanyName, ContactName from 
         Customers";
         // Create the SqlDataReader 
         //object and return it
         SqlDataReader reader =
            sqlCmd.ExecuteReader();
         return reader;
      }
}