|
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
Open Web Matrix if it isn t already open.
On the Data window toolbar, click the New Connection button. Web Matrix displays the Connect To Database dialog box.
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. |
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
In the Data window, select the Tables node.
Click the New Item button in the Data window toolbar. Web Matrix displays the Create New Table dialog box.
In the Table Name text box, type Guestbook.
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 OK to complete the table definition.
|