ASP.NET Code
  Home arrow ASP.NET Code arrow Page 5 - ASP.NET Guestbook
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? 
ASP.NET CODE

ASP.NET Guestbook
By: R. Abhiram Vikrant
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 318
    2004-03-17

    Table of Contents:
  • ASP.NET Guestbook
  • Viewing the Results
  • Setting Up the Drop Down Box
  • Connecting to the Database
  • Feeding the Database
  • Viewing Guestbook: viewcomments.aspx
  • Changing the ASP:DATALIST tag
  • Explanation of the Tags

  • 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


    ASP.NET Guestbook - Feeding the Database


    (Page 5 of 8 )


    When the user clicks the Link Label (llPost), data posting starts. We handle it by implementing the LLPOST.CLICK event handler as given below:


    Private Sub llPost_Click(ByVal sender As System.ObjectByVal e As System.EventArgsHandles llPost.Click
           Line1
    Dim insertData As DataRow DataSet11.Tables("feedback").NewRow 'create a new row
            '
    populate the datarow with data from the form
    Line2
    :        insertData("name") = txtName.Text
    Line3
    :        insertData("email") = txtEmail.Text
    Line4
    :        insertData("comments") = txtComments.Text
    Line5
    :        insertData("rating") = CInt(ddnRating.SelectedItem.Value)
    Line6
    :        DataSet11.Tables("feedback").Rows.Add(insertData'add the  populated row to the dataset
            Try
    Line7:           SqlDataAdapter1.Update(DataSet11.Tables("feedback")) '
    update the database
                
    'always close the connection
    Line8:            SqlConnection1.Close()
    Line9:            Response.Redirect("viewcomments.aspx", True)
    Line10:        Catch ex As SqlClient.SqlException
                '
    do something here
    Line11
    :        Catch ex As Exception
                
    'do something here
    Line12:        End Try
        End Sub

    Line 1: creates a new data row to insert the post data

    Line 2 - Line 5: Populates the data row with the inputs gathered from the users

    Line 6: Adds the data row to the dataset(Dataset11)

    Line 7: User inputs will not be fed to the database unless you call the adapter’s update method. We do it in this line

    Line 8: Always close the connection. Note the fact that we have included Codes inside a try and catch block.

    Line 9: Redirect the users another page

    Line 10 – Line 11: Catch the exception

    More ASP.NET Code Articles
    More By R. Abhiram Vikrant


     

    ASP.NET CODE ARTICLES

    - How to Use the ListBox Control in ASP.NET 2.0
    - How to Load XML Documents in ASP.NET 2.0
    - DataGrid Code
    - ASP.NET Guestbook
    - User Controls and Client Side Scripting
    - ASP.NET Programming with Microsoft's AS...
    - ASP.NET Basics (part 3): Hard Choices
    - ASP.NET Basics (part 2): Not My Type
    - ASP.NET Basics (part 1): Nothing But .Net
    - Directory Tree Browser
    - How to get the confirmation of Yes/No from a...
    - Complete example using custom errors and wri...
    - Paging Certain # records per page .NET style
    - General Methods of formatting and Subtractin...
    - .NET LinkButton web control





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek