Creating the Guestbook Database Table


You ll store the guestbook entries in a database table. The structure of the table is quite simple. At a minimum, you ll want to use three columns to track the visitor s name, the date, and naturally the comment itself. In addition, I suggest that you include the following columns in your table:

  • EntryID  This value will be an auto-generated sequential number that will uniquely identify each guestbook entry.

  • City  This value will allow visitors from all over to identify where other visitors to your site live.

You ll use the same WebMatrix database that you used in Chapter 9, but you ll create a new table. If you have closed Web Matrix and reopened it, you ll need to connect yourself again to MSDE. (If your connection to MSDE is still active in Web Matrix, you can skip the following procedure.)

Create a connection to the WebMatrix database

  1. Open Web Matrix if it isn t already open.

  2. On the Data window toolbar, click the New Connection button. Web Matrix displays the Connect To Database dialog box.

  3. In the Server text box, type the name of your instance of MSDE.

    Tip 

    If you can t remember the MSDE instance name, double-click the MSDE icon in the Windows system tray to display the SQL Server Service Manager dialog box. The instance name is selected in the Server drop-down list.

  4. From the Database drop-down list, select WebMatrix, and then click OK.

With the database open, you can create the new table. The procedure for creating a table will be similar to that in Chapter 9, except that you ll use different column names and types.

Create the guestbook data table

  1. In the Data window, select the Tables node.

  2. Click the New Item button in the Data window toolbar. Web Matrix displays the Create New Table dialog box.

  3. In the Table Name text box, type Guestbook.

  4. Create the columns listed in the following table:

    Column Name

    Data Type

    Comments

    EntryID

    Int

    Check Required, Primary Key, and Auto- Increment.

    EntryDate

    DateTime

    Check Required.

    GuestName

    VarChar or NVarChar

    Set Field Size to 50.

    For a guestbook, there s no need to separate first name and last name.

    EmailAddress

    VarChar or NVarChar

    Set Field Size to 50.

    City

    VarChar or NVarChar

    Set Field Size to 50.

    Comment

    VarChar or NVarChar

    Set Field Size to 1000.

    Adjust the size upward if you want to allow longer comments. Remember that when you use the VarChar data type, the data takes up only the space it needs.

When you ve finished creating the columns in the Guestbook table, the dialog box will look like this:

click to expand

  • Click OK to complete the table definition.




  • Microsoft ASP. NET Web Matrix Starter Kit
    Microsoft ASP.NET Web Matrix Starter Kit (Bpg-Other)
    ISBN: 0735618569
    EAN: 2147483647
    Year: 2003
    Pages: 169
    Authors: Mike Pope
    BUY ON AMAZON

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net