Export (0) Print
Expand All

Teacher Sample Application Guide

SQL Server 2005
 

Microsoft Corporation

April 2006

Applies to:
   Microsoft SQL Server 2005 Express Edition
   Microsoft Visual Basic 2005
   Microsoft Visual C# 2005
   Microsoft Visual Studio 2005 Starter Kit

Summary: Provides an overview of the Teacher Starter Kit, an extensible and customizable application that enables school teachers to develop database applications for recording and reporting on student enrollment and assessment grades. (6 printed pages)

Contents

Introduction
Overview
Database Schema
SQL Server Express Database Files and Visual Studio 2005
Using the Application
Issues with the ReportViewer Control
Enhancements, Additions, and Wish-List Items

Download the code samples for this article:

Visual Basic Teacher Starter Kit

C# Teacher Starter Kit

Download the sample (Visual Basic)

Download the sample (C#)

Introduction

The Teacher Starter Kit shows how easy it is to develop usable database applications in Microsoft SQL Server 2005 Express and Microsoft Visual Basic 2005 (or Microsoft Visual C# 2005). This application is targeted at school teachers who may also program. It provides an automated record of assessment grades for students in multiple courses taught by the teacher. The application comes as a Microsoft Visual Studio 2005 Starter Kit template, and it is ready to be compiled and run. You have full access to all of the source code, so that you can learn how the different features and programming techniques are implemented. You can also modify and extend the Visual Basic or Visual C# source code to meet your own specific needs. A list of ideas for extending this application is provided in this document.

Overview

In addition to being a simple, fully functional desktop application, the Teacher Starter Kit application demonstrates the use of various techniques and technologies in SQL Server 2005 Express and Visual Studio 2005. The following is a partial list of the techniques and technologies that are used in the application:

  • One-to-many, many-to-many, and lookup database tables
  • SQL outer joins
  • Typed DataSets
  • TableAdapter object
  • Winforms data-binding
  • DataGridView control
  • Single-record view
  • ReportViewer control
  • Loading objects (instead of simple data) into lists or combo boxes
  • Search and filter capabilities

Database Schema

The database schema consists of six tables, including one many-to-many mapping table (CourseStudents) and one simple lookup table (Assessment types). Figure 1 shows these tables, along with their columns, primary keys, and relationships.

Figure 1. Database schema

SQL Server Express Database Files and Visual Studio 2005

It is important to understand the way in which Visual Studio 2005 handles SQL Server 2005 Express database files. There are actually several pairs of .mdf/.ldf files (Teachers.mdf and Teachers_log.ldf). Teachers.mdf is the file that contains the actual database data, and Teachers_log.ldf is the associated log file for the database (used by the SQL Server engine). In order to simplify deployment, so that all you need to do is copy the project files, without modifying any connection strings, the application is configured so that it looks for the database files in the same directory as the executable (teacher.exe)—the Output Directory. Therefore, there is one set in the \debug directory. If you also compile for a release configuration, there will be another set in the \release directory.

In addition, there is always a set in the same directory as the other source code files, since the database files are treated by Visual Studio as project items. It is important to remember that Visual Studio normally accesses this last set of database files in the IDE, even thought they are not the same files that are accessed by the application when the application (teacher.exe) is run. This means that if you run the application and modify data in the database, you will not see these changes if you look at the default database files in Visual Studio, since they are actually different physical files. When in doubt, verify the path of the database files that you are looking at by checking the path in the Properties window.

If you select the Teachers.mdf file in Solution Explorer, and look at its properties in the Properties window, you will see that Copy to Output Directory is set to Copy if newer. This means that if the .mdf/.ldf files in the source files directory are modified in any way (such as by using Server Explorer in Visual Studio), they will be copied to the \debug (and/or the \release) directory the next time the application is run, thereby overwriting the existing files. Be sure to keep this behavior in mind, and to exercise care once you have used the Teacher application to save data in the database.

Using the Application

To use the application, SQL Server 2005 Express must be installed and running on your computer.

The Teacher application is designed around a single, tabbed main form for most of the day-to-day functionality. There are ancillary forms for adding and deleting courses and students, and for selecting students and assigning them to a specific course. Figure 2 shows the application's main form.

Figure 2. Teacher application main form

The application is designed to be course-centric. That is, everything that is displayed or done from the application is based on the selected course (in the drop-down combo box). All of the tabs relate to the currently selected course. The Manage Courses button displays a dialog box that allows you to view and/or modify all currently defined courses, or to add a new one.

The functionality of the system is divided into five areas, each with its own tab and UI. The tabs are ordered according to the typical progression of activities. The following is a summary of the functionality available on each tab.

  1. Students—This is the default view of the application. It displays a DataGridView of the students currently registered in the current course.

    Figure 3. Students view

    You can click on the columns in the grid to set the sorting of the data. Use the toolstrip to search for a student in the course, by (partial) last name. One or more existing students may be added to the course by using the Select Students dialog box. A student may be removed from the course by clicking the Remove Students button. New students may be added to the system by using the Manage Students dialog box.

  2. Assessments—This tab allows you to browse, modify, and delete existing assessments, as well as to add new ones.

    Figure 4. Assessments view

  3. Enter Grades—This is where you enter or modify a student's grade for a defined assessment. The grade is validated, to ensure that it is numeric and that it falls within the minimum/maximum range defined for that assessment (displayed as a hint).

    Figure 5. Enter Grades view

  4. View Grades—This displays a DataGridView of the existing grades currently assigned for all students and for all of the assessments in the current course. Click a column in the grid to set the sort order.

    Figure 6. View Grades view

  5. Reports—This is where you choose between the two different formats for reporting the grades for students in the current course.

    Figure 7. Reports view

    The View Report dialog box displays the report and allows for standard viewing, paging, sizing, zooming, print preview, and printing.

    Figure 8. View Report dialog box

Issues with the ReportViewer Control

The ReportViewer shown in the Figure 7 is a powerful control for previewing, printing, and exporting reports based on data in your SQL Express database. This control is not part of the Microsoft .NET Framework, but is an add-on control that is part of Visual Studio. Because of this, you need to be aware of the following points:

  • If you deploy your application on a computer that does not have Visual Studio 2005 installed, you cannot necessarily assume that the ReportViewer control is available on that computer—even after .NET Framework 2.0 is installed. This issue is easily addressed by downloading and installing the Report Viewer Redistributable onto the target computer. Alternatively, you can build a setup program from within Visual Studio (Professional Edition or better) to deploy your application on other computers. Once it is detected that your application uses the ReportViewer control, it will automatically be included as part of the setup program for your application.
  • The Visual Basic Express and C# Express versions of Visual Studio do not include the ReportViewer control. This means that if you are using Visual Basic Express or C# Express to develop an application based on the Teacher Starter Kit, you must first download and install the Report Viewer Redistributable onto your development computer in order to compile the starter kit. You must also download and install the Report Viewer Redistributable on any target machines onto which you are deploying your application.

Visual Basic Express and C# Express do not include a designer for designing reports.

Enhancements, Additions, and Wish-List Items

This application is designed and implemented to be as simple and easy-to-follow as possible. The emphasis is on correct, functional code, rather than more complex code that might be appropriate for large-scale applications. This means that, although the design and implementation are appropriate for a simple desktop application (and as a learning tool), functionality would have been implemented differently if this were meant to be a commercial and/or enterprise-class application. If you plan on modifying the existing code, the following are some things that you may want to do:

  • Move more of the code out of the actual event handlers into separate functions. This was done often, but not always, in order to make the code easier to follow.
  • Move code out of the forms into separate classes.
  • Make the overall application more event-driven.
  • Write code to have the system remember its context in more situations. The current implementation will often "reset" its context, rather than remember it. This was done in order to avoid adding a lot of code to add this functionality, which would have obscured the essential code of the application.

    An example of this behavior is the fact that the Current Course combo box is reset after you display and return from the Manage Courses dialog box, rather than retaining what was displayed.

  • Have the exception handlers in Try-Catch blocks checked for more specific exception types.

The following is a list of ideas on how you can extend the functionality of the Teacher Starter Kit application:

  • Categorize courses by department.
  • Extend the application to support multiple teachers. Each teacher could be required to have his or her own user name and password, and be able to access information for only the courses that he or she teaches.
  • Calculate a student's final grade based on assessment grades.
  • Calculate and display student and course statistics.
  • Color-code assessment types.

Modify the views of assessment grades so that you show grades for only a single assessment, or for a single student across multiple courses.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft