Fetch a Data from database to login form

In this article we will learn how to fetch a data from database to login form.
  • 2284

In this article we describe how a user can fetch a data from database using login Form. This is elementary level of fetching a data from database. By using this technique you can fetch a entire data from database on the web form.

1.Open visual studio
2.Create two web form. Here we create by name home.aspx and account.aspx.
3.Drag a panel to home.aspx web form for login box.
4.Now drag some Textboxes ,Labels and Buttons on web form

<asp:Panel ID="Panel1" runat="server" BackColor="Lime" BackImageUrl="~/App_Data/img1.JPG"BorderColor="#00CC00" Height="224px" Style="margin-left: 287px"Width="488px">&nbsp;&nbsp;<br />&nbsp;<br />    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <asp:Label ID="Label2" runat="server" Text="Username">
</
asp:Label>
&nbsp;<asp:TextBox ID="TextBox1" runat="server" Height="22px" OnTextChanged="TextBox1_TextChanged1" Width="229px" AutoCompleteType="Disabled"></asp:TextBox><br /><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<asp:Label ID="Label3" runat="server" Text="Password ">
</
asp:Label>
&nbsp;<asp:TextBox ID="TextBox2" runat="server" Width="226px" TextMode="Password"></asp:TextBox>&nbsp;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Email id&nbsp;&nbsp;&nbsp;&nbsp;<asp:TextBox ID="TextBox3" runat="server" Width="223px" AutoCompleteType ="Disabled">
</
asp:TextBox><br /> &nbsp;&nbsp;&nbsp;<br />     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="SignIn"/><br />

5.Now create database Using sqlserver .

6.Create connection for database

Partial Class _Default
Inherits System.Web.UI.Page
Dim con As SqlConnection
Dim come As SqlCommand
Dim str As String
Dim ad As SqlDataAdapter
Dim dr As SqlDataReader

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
con = New SqlConnection("Data Source =MCNDESKTOP06; Initial catalog = empinfo ; User ID = sa;Password = wintellect")
con.Open()

7.Insert the data into the database which you are created

8.Now write the code on button click event

str = (("select * from login_info  where name ='" + TextBox1.Text & "' and Password ='") + TextBox2.Text & "' and emailid ='") + TextBox3.Text & "'"
cmd = New SqlCommand(str, con)
dr = cmd.ExecuteReader()
If dr.Read() Then
Session("name") = dr.GetString(0)
Response.Redirect("account.aspx")
Else
Label4.Text = "Invalid user"
End If

Output of the application
 

_img1..jpg
After clicking button Sign In

_img2..jpg

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.