Click here to Skip to main content
16,007,885 members
Articles / Web Development / ASP.NET
Article

Performing DataBase Entry

Rate me:
Please Sign up or sign in to vote.
1.29/5 (3 votes)
8 Aug 2002 60.6K   987   26   3
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.

VB
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

VB
     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


Written By
Web Developer
United States United States
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.

Comments and Discussions

 
GeneralMy vote of 1 Pin
Hristo-Bojilov1-Sep-09 22:31
Hristo-Bojilov1-Sep-09 22:31 
GeneralRe: Data Entry Projects Pin
kingyashi1-Jul-07 21:48
kingyashi1-Jul-07 21:48 

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

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