Database
  Home arrow Database arrow Page 5 - Database Storage with the ASP.NET Web Matr...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
DATABASE

Database Storage with the ASP.NET Web Matrix
By: Dan Wellman
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 10
    2005-09-14

    Table of Contents:
  • Database Storage with the ASP.NET Web Matrix
  • Create a database and table
  • Setting up a registration page
  • Coding the page
  • Error message
  • Password security

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Database Storage with the ASP.NET Web Matrix - Error message


    (Page 5 of 6 )

    Go back to the Web Matrix and drag another label onto the page so that it sits next to the Username textbox.  Make the text red and remove the Text value once again, and this time, set the ID to lblUsernameError.

    Now in order to catch the exception thrown by SQL when a pre-existing value is passed to the table, you just need to add two lines of code to the INSERT function.  Near the bottom of the function is the Try structure that attempts to write to the database.  Add the following statement directly below the rowsAffected = dbCommand.ExecuteNonQuery:

    Catch e as Exception
       lblUsernameError.Text = "* This username has already been
    taken"

    Save the file and run it again, attempting to add a duplicate username.  Your red error message should be displayed on the page. 

    Once either of these messages has been displayed, they remain on the page even after a refresh.  A simple way to stop this is to add the following code to the top of the btnSubmit_Click sub:

    lblUsernameError.Text = ""
    lblPasswordError.Text = ""

    Now if the problem is corrected by the user, and the form is resubmitted successfully, the red error messages disappear.  For the sake of completeness, you can also add at this point a confirmation message when the operation is a success.  In the Design view of the Web Matrix, drag a final label to below the two buttons; set the fore color to green this time and the ID to lblSuccess.  Remove the Text value.

    Now head back to the INSERT function and find the Finally statement of the Try code block.  Below the connection close call, add this method:

    lblSuccess.Text = "Thank you for registering, yada, yada, yada"

    Run the page again and a successful submission will result in the green message.

    More Database Articles
    More By Dan Wellman


       · Hi,This article explores the first of the built in Code Wizards that allow you...
     

    DATABASE ARTICLES

    - Excel Reference
    - Database Programming in C# with MySQL : Usin...
    - Formatting Techniques for Data Access from E...
    - Data Access from Excel VBA
    - Generating a Multiple Table Crystal Report u...
    - ADO and the Command Object
    - On Wiring Up an ADO Data Control
    - Reading and Writing to Files on the Intranet
    - Using ADO Record to Create and Navigate Intr...
    - Using Data Access Pages to Access Data on a ...
    - Using ADO with the SQL Native Client
    - ADO`s Stream Object
    - Opening a Record Object Referencing an Open ...
    - Introducing Jasper (SQL Anywhere 10 Beta)
    - Creating a Database Project in VS 2005





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT