Creating the Slideshow Tables


To start, let s create the database tables that you ll need to store slideshow and slide information. In this section, you ll also enter some test data directly into the database. You ll create the tables in the same WebMatrix database you used in previous chapters.

Create the Slideshow table

  1. If you ve closed Web Matrix since the last time you worked with data, you ll need to re-create the connection to the WebMatrix database. To reconnect, follow the instructions in Chapter 10 for creating a connection to the database.

  2. In the Data window, open the node for your server. Select the Tables node, and click the New Item button in the Data window toolbar to display the Create New Table dialog box.

  3. In the Table Name box, type Slideshows.

  4. Create the columns listed in the following table:

    Name

    Data Type

    Comments

    SlideshowName

    Varchar

    Check Required and Primary Key

    Set Field Size to 15.

    SlideshowTitle

    Varchar

    Check Required

    Set Field Size to 70.

When you ve finished, the dialog box will look like the following illustration:

click to expand

For the Slideshows table, you re not using an auto-increment primary key as you ve done with tables in previous chapters. Instead, you ll enter a short name for the slideshow, up to 15 characters. You can use a code, an abbreviation, or even a number to identify your slideshows. The slideshow name you use isn t important, because you re the only one who ever sees it. You could use an auto-increment primary key, but using a key that you enter explicitly, instead of letting MSDE assign a key when you create new records, will have advantages later on because it will be easier to remember the slideshow names when you re entering slide details.

  • Click OK to save the table definition.

  • After you ve finished defining the Slideshows table, double-click the Slideshows table in the Data window. Web Matrix displays the Edit Table dialog box, in which you can enter some data. In the Edit Table dialog box for the Slideshows table, enter two or three slideshow records. For the SlideshowName column, enter a number, an abbreviation, or a code. The format doesn t matter, as long as it s unique for each slideshow entry. Be sure to make a note of the values that you re using for the SlideshowName column; you ll need these values for entering slides, which you ll do shortly. Figure 12-3 shows some sample records for the Slideshows table.

    click to expand
    Figure 12-3: Sample data for the Slideshows table.

    When you ve finished entering the records, click Close. Now let s move on and create the Slides table.

    Create the Slides table

    1. Create a new table and name it Slides.

    2. Create the column definitions listed in the following table:

      Name

      Data Type

      Comments

      SlideID

      Int

      Check Required, Primary Key, and Auto-increment

      SlideshowName

      Varchar

      Check RequiredSet Field Size to 15.

      SlideUrl

      Varchar

      Check RequiredSet Field Size to 65.

      SlideCaption

      VarChar

      Check RequiredSet Field Size to 250.

      SlideDate

      VarChar

      Check RequiredSet Field Size to 50.

    In the Slides table, unlike the Slideshows table, we want to use an auto-increment primary key. The SlideUrl column will contain the location (path or URL) of the graphics file for this slide. The SlideDate column is set to use the VarChar data type instead of the DateTime data type. The DateTime data type requires you to enter a complete date with month, day, and year. For our slides, however, we re willing to accept dates such as February 2002 or even Early 1974 date- like data rather than actual dates. The disadvantage is that we won t be able to sort the slides by date or at least, not meaningfully.

  • Click OK to close and save the table design. The next step is to enter some slides to go with the Slideshow records you entered earlier. Double- click the Slides table in the Data window to open the Edit Table dialog box.

  • Enter some slides. In the SlideshowName column, type the code or abbreviation for the slideshow that the slide belongs to. You ll need the SlideshowName column s values that you noted earlier from the Slideshows table. If you want to really test the facilities of your slideshow application, make two entries in the Slides table for the same picture but assign each entry to a different slideshow.

  • In the SlideUrl column, enter the relative path for the graphics file. For example, if a graphics file is in the path C:\WebMatrix\images\vacation\vacation1.jpg, type just images\vacation\vacation1.jpg. As I explained in Chapter 5, you should not use an absolute path for the value of the SlideUrl column. For the values of the SlideCaption and SlideDate columns, enter anything you want, but be sure to enter some text.

  • I realize that entering slide records in the Edit Table grid is cramped and annoying sorry about that. In Chapter 13, you ll create some Web pages that will let you enter data into master and details tables such as Slideshows and Slides. For now, however, let s move on to create the Web pages for this chapter.




    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