Categories
Visual Basic 6.0

Login with SQL Server Database in Vb6

This is a sample login application that use in your project application system in VB6. Let’s start coding.

Create a Module copy the codes below for database connection in order to connect to the SQL Server database and put the following code inside it.

Option Explicit

'variables for ADODB
Global Connect As New ADODB.Connection

Public Sub SQLDB(adoObj As Adodc, AdoRec As String) 'for SQL Recordsource
'Connection string: workstation id=koroikadb.mssql.somee.com;packet size=4096;user id=xxxxxx;pwd=yyyyyy;data source=koroikadb.mssql.somee.com;persist security info=False;initial catalog=koroikadb
    'Loads the database and provides the database password
    adoObj.ConnectionString = "Provider=sqloledb;user id=;pwd=;Data Source=(local);persist security info=False;Initial Catalog=Tutorial;Trusted_Connection=Yes;"
    
    'Sets the command type to Table
    adoObj.CommandType = adCmdText
    
    'Loads the source table of info
    adoObj.RecordSource = AdoRec

    'refreshes database status
     adoObj.Refresh
End Sub

Sub Main()
On Error Resume Next
Call SQLDB(Form1.Adodc1, "Select * from tblSecurity ")
If Form1.Adodc1.Recordset.RecordCount = 0 Then
    Form1.Adodc1.Recordset.AddNew
    Form1.Adodc1.Recordset.Fields("USERNAME") = "admin"
    Form1.Adodc1.Recordset.Fields("PASSWORD") = "admin"
    Form1.Adodc1.Recordset.Update
End If

Form1.Show
End Sub

After creating module we need to create form to your project and double click the form to enter the code window Copy the code below and paste then save it.

Private Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.Image1.Picture = Me.Image3.Picture
End Sub

Private Sub Image2_Click()
On Error Resume Next
If Me.Text1.Text = "" Or Me.Text2.Text = "" Then
MsgBox "Login and password should not be blank", vbInformation, "Login"
Exit Sub
End If

Call SQLDB(Me.Adodc1, "Select * from tblSecurity where USERNAME='" & Me.Text1.Text & "' and PASSWORD='" & Me.Text2.Text & "'")
If Me.Adodc1.Recordset.Fields("USERNAME") = Me.Text1.Text Then
   MsgBox "Please input correct username and password", vbCritical, "Login"
Else
    Unload Me
    Form2.Show
End If
End Sub

Private Sub Image2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.Image1.Picture = Me.Picture1.Picture
End Sub

For more information about the system. You can contact me @
Email – larrydaveemol@gmail.com
FB Account – https://www.facebook.com/larrydavelacapagemol

Let me know what you need just leave a message/comment and I will do my very best to make that happen. I hope this codes will help you. Enjoy Coding!

Share this
  •  
  •  
  •  
  •  
  •  
  •  
  • 42
    Shares

Leave a Reply

Your email address will not be published. Required fields are marked *