Click here to Skip to main content
Licence 
First Posted 8 Aug 2002
Views 52,810
Bookmarked 26 times

Performing DataBase Entry

To illustrate record entry in to a SQL Database

Sample Image - DbEntry.jpg

Introduction

This article demonstrates the use of SqlConnection and SqlAdapter to login to a page and make data entry in to a SQL Database.

This was coded in ASP.NET . The application opens with a login page and no validation mechanism is provided to check the user validity and the page navigates into another page , where the user is allowed to make an entry in to a form which asks a name and a phone number. The input data is stored in a database which is created using SQL Server.

A sample code will explain how it is performed.

 Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        TextBox1.TextMode = TextBoxMode.Password
    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If (TextBox1.Text <> "" & TextBox2.Text <> "") Then
            Response.Redirect("Introduction.aspx?name=" & System.Web.HttpUtility.UrlEncode(TextBox2.Text & " " & TextBox1.Text))
        Else
            Response.Write("Please Enter a valid Name and Password")
        End If
    End Sub

The following code performs insertion into the database

     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If (TextBox1.Text <> "" And TextBox2.Text <> "") Then
         
            Dim MyConnection = New System.Data.SqlClient.SqlConnection("server=(local)\NetSDK;database=PhoneDatabase;Trusted_Connection=yes")

            Dim MyCommand As System.Data.SqlClient.SqlCommand
            Dim InsertCmd As String = "insert into Phone values('" + TextBox1.Text + "'," + TextBox2.Text + ")"
'requires validation to be performed. None done here
            MyCommand = New System.Data.SqlClient.SqlCommand(InsertCmd, MyConnection)
            MyCommand.Connection.Open()

            MyCommand.ExecuteNonQuery()
            MyCommand.Connection.Close()
        End If
        Response.Redirect("Introduction.aspx")
    End Sub

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Ragavendran Vaidhyanadhan

Web Developer

United States United States

Member

Ragavendran was born in South India. He holds a Bacnelor of Computer Science and Engineering. Currently he works as a Software Engineer. He is techno Savvy and All he wishes to do in life is to get to know a lotta things....
He is always intrigued about learning new things.
 
His skills include C,C++,Java ,.NET.He also experience working in Legacy Systems. He feels most comfortable with C++ and Java.
Computers are his first love and he likes reading books, music and trekking.
 
He is a voracious reader and loves reading books. A Leo by birth, he loves trekking and gardening. One of his main ambitions is to write his autobiography, though he is not sure who will read it.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 1 PinmemberHristo Bojilov22:31 1 Sep '09  
GeneralMessage Removed PinsussAnonymous1:52 5 Mar '04  
GeneralRe: Data Entry Projects Pinmemberkingyashi21:48 1 Jul '07  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120517.1 | Last Updated 9 Aug 2002
Article Copyright 2002 by Ragavendran Vaidhyanadhan
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid