
Imports System.Data.SqlClient

Public Class Form1
    
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Call main()

        Con.Open()

        Dim cmd As New SqlCommand("SELECT * FROM tblogin WHERE username= '" & txtuser.Text & "' AND password = '" & txtpass.Text & "' AND  utype = '" & cmbuser.Text & "'", Con)
        Dim sdr As SqlDataReader = cmd.ExecuteReader()

        If (sdr.Read() = True) Then
            Form2.tolmenu.Enabled = True
            Form2.txtuser.Text = txtuser.Text
            Form2.txtutype.Text = cmbuser.Text
            Me.Hide()
        Else
            MessageBox.Show("Invalid username or password!")

        End If

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        searchrcv()
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        txtuser.Text = ""
        txtpass.Text = ""
        cmbuser.Text = ""
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        End
    End Sub
    Private Sub searchrcv()
        Call main()
        Con.Open()

        Dim cmd As New SqlCommand("SELECT username FROM tblogin", Con)

        Dim ds As New DataSet
        Dim da As New SqlDataAdapter(cmd)
        da.Fill(ds, "My List") 'list can be any name u want

        Dim col As New AutoCompleteStringCollection
        Dim i As Integer
        For i = 0 To ds.Tables(0).Rows.Count - 1
            col.Add(ds.Tables(0).Rows(i)("username").ToString())
        Next
        txtuser.AutoCompleteSource = AutoCompleteSource.CustomSource
        txtuser.AutoCompleteCustomSource = col
        txtuser.AutoCompleteMode = AutoCompleteMode.Suggest
        Con.Close()

    End Sub
End Class