Database
  Home arrow Database arrow Page 4 - 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  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
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 - Coding the page


    (Page 4 of 6 )

    This is all the page needs visually, the rest will be code run behind the scenes.  Switch to the Code view using the tabs at the bottom of the document window.  The Code Wizards toolbox will appear.  From here, drag the INSERT Data Method onto the page to open the INSERT Data Code Wizard dialog box.  Your database, unless you have more than one configured connection, will appear in the Select a Database box, so click the next button.  Make sure your logins table is selected in the next window and simply click Next again (neither of the columns in the right-hand panel need to be ticked).  Now just choose a name for your method, like NewUser, and click Finish.

     

    Your code page should now contain the block of code needed to write data to your table.  Before this can happen however, you need to define a way of calling the function and telling it what data to write.  Go back to the Design view of the document page and double click the submit button, which will create a new onclick event handler for the button, and add some more code to the Code view.

    Switch back to the Code view and in between the new code that has been added type:

    If txtPassword.Text <> txtPassword2.Text Then
          lblPasswordError.Text = "* Verify password must match
    password"
    Else
          NewUser(txtUsername.Text, txtPassword.Text)
    End if

    This is all that is needed to check that the two password fields match and if so, call the function and pass it the contents of each text box as a parameter.  When the password fields do not match, the text property of the label following the verify password box is set to the error message.  This needs to be done because, unfortunately, the MessageBox.Show VB.NET method does not work with ASP.NET.

    To create functionality for the clear button, switch back to the Design view and double click the clear button.  In between the lines of new code added to the Code view, add:

    txtUsername.Text = ""
    txtPassword.Text = ""
    txtPassword2.Text = ""

    To test the page so far, click the play button at the top of the Web Matrix.  Assuming all is well, if you enter a username and password into the text boxes and click the submit button, the text entered will be written to your database table.  To verify this, go back to the Web Matrix and double click the table in the Data Pane. 

    Once thing you should remind yourself of at this point is that we set the IsUniqueKey of the username column of our data table to true, therefore, if you try to enter the same username on the form twice, you’ll get a nasty looking error page.  Users should not be subject to this kind of abuse, so you’re going to want something that will present a proper error message to the user.  You can use the same display method for the error as the verify password message above.

    More Database Articles
    More By Dan Wellman


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

    DATABASE ARTICLES

    - Converting Your Excel Worksheet into a Worki...
    - 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)





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    Stay green...Green IT