1 / 14

Lesson 11

Lesson 11. Adding Record To Your Database. Create a new page and call it AddRecords.aspx. Adding Records. Add to your workspace area. Type and center More Movie Data: On the left side of the workspace type the following: Enter Movie Name: Enter Actor: Enter Actress: Enter Director:

kare
Download Presentation

Lesson 11

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lesson 11 Adding Record To Your Database

  2. Create a new page and call it AddRecords.aspx Adding Records

  3. Add to your workspace area • Type and center More Movie Data: • On the left side of the workspace type the following: • Enter Movie Name: • Enter Actor: • Enter Actress: • Enter Director: • Enter Release Date: • Enter Rating: • Enter MPAA: • Enter Run Time:

  4. Add Textbox • Drag a TextBox and place it to the right of field names you just entered (Use Absolute Position found under the Layout menu for placement

  5. Add a button • Drag a button and place in the middle

  6. Label Message • Drag a Label and place it below the button • On the label properties, do the following: • To the right of ID type labelMessage • Select Fore Color to be Red • Aside of Text Delete the word Label

  7. Adding ButtonEvent Code • Click on Code View • Drag an INSERT Data Method • Select the Movies Database and click OK • Click Next and name the Method AddMovieRecord

  8. Insert Code • Go back to Design View and double click the button • Before the End Sub type • Dim MovieName As String • Dim Actor As String • Dim Actress As String • Dim Director As String • Dim ReleaseDate As DateTime • Dim Rating As String • Dim MPAA As String • Dim RunTime As String You have just created variables for all your fields used in the database

  9. More Code To Add • MovieName= Server.HtmlEncode (TextBox1.Text) • Actor= Server.HtmlEncode (TextBox2.Text) • Actress= Server.HtmlEncode (TextBox3.Text) • Director= Server.HtmlEncode (TextBox4.Text) • ReleaseDate= Server.HtmlEncode (TextBox5.Text) • Rating= Server.HtmlEncode (TextBox6.Text) • MPAA= Server.HtmlEncode (TextBox7.Text) • RunTime= Server.HtmlEncode (TextBox8.Text)

  10. Server.HtmlEncode Coversion • For the variables you created you must then pass the information to those variables with this conversion • Remember the AddMovieRecord method you created? This is now going to be used in your code

  11. Passing Values To Your Database • Continue to type this code: • Try • AddMovieRecord (MovieName, Actor, Actress, Director, ReleaseDate, Rating, MPAA, RunTime) • labelMessage.Text= "Your movie record has been updated, Thanks" • Button1.Enabled = False • Catch • labelMessage.Text= "Please submit again there was an error" • End Try

  12. Error Checking Code • The Try-Catch block is for error checking • You can see the two messages that were created and will be displayed in entries were successful or unsuccessful

  13. Entering Records • Press F5 and load the new page • Enter the following record to your Movie database

  14. Update • You can see that your movie record has been updated successfully • For now you can go back to Web Matrix and click on data and view the updated JamesBondSeries Table with you your new record

More Related