Find missing record using query

After running the query to update table records the record(s) is missing. Run this query to find the missing record.


SELECT Table1.column
FROM Table1
LEFT JOIN Table2 ON
Table1.column = Table2.Column
WHERE Table2.column is NULL;

* Replace Table1 and *2 with your table names

VB.NET – Login form – create user session

This post will guide you through designing the login form with SQL backend and creating a user session.

Learn more about new promotions!
login.aspx

login.aspx (markup code)

<%@ Page Title="" Language="VB" MasterPageFile="~/Default.Master"
AutoEventWireup="false" CodeFile="login.aspx.vb" Inherits="_login" %>
<asp:Content ID="HeaderContent" runat="server"
ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server"
ContentPlaceHolderID="MainContent" >

<table border="0" cellpadding="1" cellspacing="0">
   <tr>
      <td colspan="2">Login:</td>
   </tr>
   <tr>
      <td colspan="2>
     <br />
     <asp:label ID="ssError" runat="server"></asp:label></td>
     </tr>
     <tr>
      <td align="right">Username: </td>
      <td>
      <asp:textbox ID="usn" runat="server" ToolTip="username"
      CssClass="loginBox" ></asp:textbox>
      <asp:requiredfieldvalidator ID="RVusn" runat="server"
      ErrorMessage="*" ControlToValidate="usn" >
      </asp:requiredfieldvalidator></td>
   </tr>
   <tr>
       <td align="right">Password: 
       <td>
       <asp:textbox ID="pwd" runat="server" TextMode="Password"
       ToolTip="password" CssClass="loginBox" ></asp:textbox>
      <asp:requiredfieldvalidator ID="RVpwd" runat="server"
      ErrorMessage="*" ControlToValidate="pwd">
      </asp:requiredfieldvalidator></td>
   </tr>
   <tr>
      <td colspan="2"> </td>
   </tr>
   <tr>
      <td colspan="2" class="text">
      <asp:imagebutton ID="Login" runat="server"
      ImageURL="/images/buttons/btn_signin.gif" />
      </td>
   </tr>
 </table>
</div>
</asp:Content>

login.aspx.vb (code behind)

Imports System.IO
Imports System.Data.OleDb
Imports System.Web.UI.WebControls.ImageButton
Imports System.Web.UI.WebControls.TextBox
Imports System.Web.SessionState
Imports System.Web.Security
Imports System.Web
Partial Class _ss_login
  Inherits System.Web.UI.Page
   Protected Sub Login_Click(ByVal sender As Object, _
     _ByVal e As System.Web.UI.ImageClickEventArgs)
              Handles Login.Click
     '/ defining variables/controls
      Dim usn As TextBox
      Dim pwd As TextBox

      'binding controls
       usn = Login.FindControl("usn")
       pwd = Login.FindControl("pwd")

       Dim user As String
       Dim key As String
       user = usn.Text.ToString()
       key = pwd.Text.ToString()

   'encrypt password
    Dim sha1Obj As _
    New System.Security.Cryptography.SHA1CryptoServiceProvider
     Dim bytesToHash() As _
       _Byte = System.Text.Encoding.ASCII.GetBytes(key)
    bytesToHash = sha1Obj.ComputeHash(bytesToHash)

    Dim keyCode As String = ""
    For Each b As Byte In bytesToHash
        keyCode += b.ToString("x2")
     Next

     '/ sql oledb connection * you can define your own sql connection
     Dim ConnDB As_
       _New OleDbConnection("Provider=sqloledb;Data Source=mySqlServer;
     Initial Catalog=mySqlDB;Persist Security Info=True;_
       _User ID=myUsr;Password=myPwd")
     Dim cmd As New OleDbCommand("SELECT * FROM ss_users WHERE
                                (u_user_name = '" & usn.Text.ToString() & "')
                                AND
                                (u_password = '" & keyCode & "');", ConnDB)
     Dim reader As OleDbDataReader

     Try
       '/ open connection
       cmd.Connection.Open()
       reader = cmd.ExecuteReader()
       If reader.Read() Then
         'create sessions
          Session("Name") = reader(6).ToString()
          Session("ID") = reader(0).ToString()
          Session("LastLogIn") = reader(11).ToString()
          Response.Redirect("default.aspx")  'page of your choice
       Else
          ssError.Text = ("Error - please try again.")
       End If
       cmd.Connection.Close()
       Catch ex As Exception
          ssError.Text = "Error: " & ex.Message.ToString()
       End Try
    End Sub
End Class

Related posts:
End User Session

VB.NET – End user session

To end user session and disable user from using a back button to go back to secure page, you need two pages i simply named killsession.aspx and logout.aspx. I will explain both pages with code behind and markup code.

killsession.aspx

killsession.aspx (markup code)


< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <div>
    </form>
</body>
</html>

killsession.aspx.vb (code behind)


Partial Class Close_Session
  Inherits System.Web.UI.Page
  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
                          Handles Me.Load
      Session.Clear()
      Session.Abandon()
      Session.Remove("Name")

      Response.Redirect("logout.aspx")

    End Sub
End Class

logout.aspx

logout.aspx (markup code)

<%@ Page Language="VB" AutoEventWireup="false"
CodeFile="logout.aspx.vb" Inherits="logout" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>
    <script language="javascript">
    //disable user from going back //
        function doLogout() {
            history.go(+1)
        }
        </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    </div>
    </form>
</body>
</html>

logout.aspx.vb (code behind)

Partial Class logout
  Inherits System.Web.UI.Page
  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
                       Handles Me.Load
       'fire-up java code from a markup page
        If (Not ClientScript.IsStartupScriptRegistered("doLogout")) Then
            Page.ClientScript.RegisterStartupScript _
            (Me.GetType(), "history", "doLogout();", True)
        End If
        'redirect user to a page of your choice
         Response.Redirect("default.aspx")
    End Sub
End Class

Related posts:
Disable Back Button