1. Home
  2. Computing & Technology
  3. Visual Basic

Learn ASP.NET 2.0 - ASP.NET 2.0 Code-Behind and Database Updating
Adding a database to AVBAsk

By , About.com Guide

Apr 20 2008

The AVBAsk application that was started earlier will do some validation checking on the data entered into the server controls and send a message via email. But it would be very nice if it also kept track of emails sent. That's a job for a database.

To make sure that you had SQL Server 2005 Express (SSE from now on) installed and working, a test database was added to a website in part 2 of this tutorial, SQL Server and ASP.NET. If you have any trouble here, you might want to read through part 2 again. In addition, the application we're building was created in parts 3 and 4. If you don't have that website, you can go through those to create the base application that is being updated here.

Using the AVBAsk website that was last coded in part 4 and using the same methods explained in part 2, add a SSE database to the website:

Database name: AVBQuestions.mdf
Table name: AVBQuestion
Columns:
   AVBQuestionKey
      int
      SetPrimaryKey
   AVBQuestionFrom
      nvarchar(50)
   AVBQuestionSubject
      nvarchar(50)
   AVBQuestionMessage
      nvarchar(MAX)
   AVBQuestionDate
      datetime

Uncheck all of the Allow Nulls checkboxes except AVBQuestionMessage.

In part 2 of the tutorial, we used a uniqueidentifier as the key type. But a 128 bit GUID is really too much for our application since we really only need a key that will identify each row of the table. So this time, use a type int as the key and change Is Identity to Yes in the Column Properties for AVBQuestionKey. The starting value (Identity Seed) and the increment (Identity Increment) should change to their default value of 1 automatically. Identities are often used as keys for tables. SSE will guarantee that a new value that hasn't been used before will be used whenever a new row is inserted into the database. In fact, you will find that you can't enter data into the column value manually.

The completed database is shown below:

--------
Click Here to display the illustration
Click the Back button on your browser to return
--------

Explore Visual Basic
By Category
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Visual Basic
  4. Learn VB.NET
  5. Learn ASP.NET
  6. Learn ASP.NET 2.0 - ASP.NET 2.0 Code-Behind and Database Updating

©2009 About.com, a part of The New York Times Company.

All rights reserved.