Create Two Tier Business Web Application with ADO.Net

About this Tutorial –

Objectives –

Delegates will learn to develop applications using C #4.0 After completing this course, delegates will be able to:

  • Use Visual Studio 2010 effectively
  • Create Two Tier Business Web Application with ADO.Net


This course has been designed primarily for programmers new to the .Net development platform. Delegates experience solely in Windows application development or earlier versions of ASP.Net will also find the content beneficial.


Before attending this workshop, students must:

  • Be able to manage a solution environment using the Visual Studio 2010 IDE and tools
  • Be able to program an application using a .NET Framework 4.0 compliant language


Copyright 20/12/12 – David Ringsell

Download Solutions

Java tutorial

Exercise 1
Create a Customer Class that reads details from the Northwind database

In this exercise, you will create a customer class in a web application. The class will contain a method that reads the customers table.

Create Two Tier Business Application

  1. Create an empty Web Application project called Business Application.
  2. Add a class file called Customers.cs to the project.
  3. Import the these namespaces in to the class:
    using System.Data.SqlClient;
    using System.Data;
  4. Declare at class level these ADO.Net objects:
    private SqlConnection conn;
    private SqlDataAdapter da;
    private DataSet ds;
  5. Add a GetCustomers() method that returns a DataSet to the class.
  6. Add code to GetCustomers() that reads data from the Customers table and copies this to the DataSet: – change the name of DataSource to your instance of SQL Server.
    public DataSet GetCustomers()
    conn = new SqlConnection(@"DataSource=.; Initial
    Catalog=Northwind;Integrated Security=True");
    string queryString
    ="SELECT CustomerID, CompanyName FROM dbo.Customers";
    da = new SqlDataAdapter(queryString, conn);
    ds = new DataSet();
    da.Fill(ds, "Customers");
    return ds;
  7. View code file.

Exercise 2
Show Customer Data on a Web Form

In this exercise, you will add a web form that shows customer data. The form will use the customer class to access the database.

Design a web form

  1. Add a web form called Default.aspx to the project. Set this as the start page.
  2. Add a GridView control to Default.aspx called gvCustomers.
  3. In the form’s Page_Load event handler create a Customers object & call the GetCustomers method.
    Customers custObject = new Customers();
    DataSet ds = custObject.GetCustomers();
  4. Bind the GridView to the DataSet returned from the GetCustomers method.
    gvCustomers.DataSource = ds.Tables["Customers"];
  5. View code file.
  6. Run the application to test if customer data is displayed.
  7. Enhance the application, for example:
    • Allow customer data to be updated.
    • Move the Customer class to a separate project
    • Improve the UI

Back to beginning

If you liked this post, please comment with your suggestions to help others.
If you would like to see more content like this in the future, please fill-in our quick survey.
Scroll to Top