create a login form that checks info against a database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • peterhinett
    New Member
    • Nov 2007
    • 8

    create a login form that checks info against a database

    Hi. iv been able to create a loin form bu I am stuck on the code. what i want is for a manager to be able to enter his manager ID and password and it to be checked against a database. I have set up the various connections but I cant figure out the code.
    Thanks
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    when the user logs in to database using username and password

    1.check for existance of the user name and the corresponding password .
    2. if it exists then login.
    else
    deny login.

    Comment

    • jamesd0142
      Contributor
      • Sep 2007
      • 471

      #3
      Here's an example using sql server 2000

      [code=vbnet]Imports System.Data.Ole Db

      Public Class Form1

      '---Database Declarations
      Dim Cmd As OleDb.OleDbComm and
      Dim Con As OleDb.OleDbConn ection
      Dim Sql As String = Nothing
      Dim Reader As OleDb.OleDbData Reader
      Dim ComboRow As Integer = -1
      Dim Columns As Integer = 0
      Dim Category As String = Nothing
      Dim da As System.Data.Ole Db.OleDbDataAda pter
      Dim oDS2 As New System.Data.Dat aSet

      Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click
      oDS2.Clear()
      Dim Password As String
      Sql = "select * from Users where [Login] = " & "'" & txtLogin.Text & "'"
      Con = New OleDbConnection ("Provider=sqlo ledb;Data Source=Server;I nitial Catalog=Databas e;User ID=sa;Password= Password")
      Con.Close()
      Cmd = New OleDb.OleDbComm and(Sql, Con)
      Try
      Con.Open()
      da = New OleDbDataAdapte r(Sql, Con)
      da.Fill(oDS2, "login")
      If oDS2.Tables("lo gin").Rows.Coun t = 1 Then
      Password = oDS2.Tables("lo gin").Rows(0)(" Password")

      If txtPassword.Tex t = Password Then
      'login successful
      Form2.Show()
      Me.Hide()
      End If
      End If
      Catch
      End Try
      End Sub
      End Class
      [/code]

      Comment

      Working...