This Way:
HTML:
<form id="form1" runat="server">
<div>
User Name
<asp:TextBox ID="txtUserName" runat="server" />
<br />
Password
<asp:TextBox ID="txtPassword" runat="server" />
<asp:Button ID="btnLogin" runat="server" Text="Login" OnClick="LoginToWebSite" />
</div>
</form>
VB:
Dim constr As String = ConfigurationManager.ConnectionStrings("ConString").ConnectionString
Protected Sub LoginToWebSite(ByVal sender As Object, ByVal e As EventArgs)
Dim sqlStatment As String = "SELECT UserName,Password FROM [Users]"
Using con As New SqlConnection(constr)
Using cmd As New SqlCommand(sqlStatment, con)
Using da As New SqlDataAdapter(cmd)
Dim ds As New DataSet()
da.Fill(ds)
Dim userName As String = ds.Tables(0).Rows(0)("UserName").ToString()
Dim password As String = ds.Tables(0).Rows(0)("Password").ToString()
If userName = Me.txtUserName.Text.Trim() AndAlso password <> Me.txtPassword.Text.Trim() Then
Dim sqlLastTime As String = "SELECT [LastPaswordChangedDate] FROM [Users]"
SelectDateTime(sqlLastTime)
End If
End Using
End Using
End Using
End Sub
Private Sub SelectDateTime(ByVal query As String)
Using con As New SqlConnection(constr)
Using cmd As New SqlCommand(query, con)
Using da As New SqlDataAdapter(cmd)
Dim ds As New DataSet()
da.Fill(ds)
Dim message As String = "Last time you changed the password at this date" + ds.Tables(0).Rows(0)("LastPaswordChangedDate").ToString()
Dim sb As New System.Text.StringBuilder()
sb.Append("<script type = 'text/javascript'>")
sb.Append("window.onload=function(){")
sb.Append("alert('")
sb.Append(message)
sb.Append("')};")
sb.Append("</script>")
ClientScript.RegisterClientScriptBlock(Me.[GetType](), "alert", sb.ToString())
End Using
End Using
End Using
End Sub
Import NameSapace:
Imports System.Configuration
Imports System.Data.SqlClient
Imports System.Data
SQL:
CREATE TABLE [dbo].[Users](
[UserId] [int] IDENTITY(1,1) NOT NULL,
[Username] [nvarchar](20) NOT NULL,
[Password] [nvarchar](20) NOT NULL,
[Email] [nvarchar](30) NOT NULL,
[CreatedDate] [datetime] NOT NULL,
[LastPaswordChangedDate] [datetime] NULL,
CONSTRAINT [PK_Users] PRIMARY KEY CLUSTERED
(
[UserId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
Thank You.