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
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 + ")"
MyCommand = New System.Data.SqlClient.SqlCommand(InsertCmd, MyConnection)
MyCommand.Connection.Open()
MyCommand.ExecuteNonQuery()
MyCommand.Connection.Close()
End If
Response.Redirect("Introduction.aspx")
End Sub
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.