About this Tutorial –
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
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 an empty Web Application project called Business Application.
- Add a class file called Customers.cs to the project.
- Import the these namespaces in to the class:
- Declare at class level these ADO.Net objects:
private SqlConnection conn;
private SqlDataAdapter da;
private DataSet ds;
- Add a GetCustomers() method that returns a DataSet to the class.
- 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
="SELECT CustomerID, CompanyName FROM dbo.Customers";
da = new SqlDataAdapter(queryString, conn);
ds = new DataSet();
- View code file.
In this exercise, you will add a web form that shows customer data. The form will use the customer class to access the database.
- Add a web form called Default.aspx to the project. Set this as the start page.
- Add a GridView control to Default.aspx called gvCustomers.
- In the form’s Page_Load event handler create a Customers object & call the GetCustomers method.
Customers custObject = new Customers();
DataSet ds = custObject.GetCustomers();
- Bind the GridView to the DataSet returned from the GetCustomers method.
gvCustomers.DataSource = ds.Tables["Customers"];
- View code file.
- Run the application to test if customer data is displayed.
- Enhance the application, for example:
- Allow customer data to be updated.
- Move the Customer class to a separate project
- Improve the UI