<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="loginUser.ascx.vb" Inherits="TEST.loginUser" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<script runat="server">
Sub submit_click(ByVal sender As Object, ByVal e As EventArgs)
Dim user As String = Me.txtuser.Text
Dim pass As String = Me.txtpass.Text
Dim objCon As SqlConnection
Dim objCmd As SqlCommand
Dim sql As String
Dim strConnection As String = ConfigurationManager.ConnectionStrings("strConnection").ConnectionString
Dim intNumRows As Integer
Try
sql = "select count(*) from username where uid = '" & user & "' and password = '" & pass & "'"
objCon = New SqlConnection
With objCon
.ConnectionString = strConnection
.Open()
End With
objCmd = New SqlCommand
With objCmd
.Connection = objCon
.CommandText = sql
.CommandType = CommandType.Text
End With
intNumRows = objCmd.ExecuteScalar
If intNumRows > 0 Then
Session.Add("username", user)
Response.Redirect("addData.aspx")
Else
MsgBox("username or password is incorrect !!!")
End If
Catch ex As Exception
MsgBox(ex.message)
End Try
objCon.Close()
objCon = Nothing
End Sub
</script>
<asp:Panel ID="PaneLogin" runat="server">
<asp:Label ID="Label1" runat="server" Text="username: " Width="100px"></asp:Label>
<asp:TextBox ID="txtuser" runat="server" MaxLength="12" Width="200px"></asp:TextBox>
<asp:RequiredFieldValidator ID="checktxtuser" runat="server"
ErrorMessage="*Username Require" ControlToValidate="txtuser"></asp:RequiredFieldValidator>
<br />
<asp:Label ID="Label2" runat="server" Text="password: " Width="100px"></asp:Label>
<asp:TextBox ID="txtpass" runat="server" MaxLength="12" Width="200px"
TextMode="Password"></asp:TextBox>
<br />
<asp:Label ID="Label3" runat="server" Text="" Width="100px"></asp:Label>
<asp:Button ID="btnsubmitLogin" runat="server" Text="Login" OnClick="submit_click" />
<br />
<a href="start.aspx">Register</a>
</asp:Panel>