Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Data
- Imports System.Data.SqlClient
- Public Class frmLogin
- Dim userName As String
- Dim extrainfo As String
- Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click
- If ConnectToSQL() Then
- Dim frm As New frmQuality(userName, extrainfo)
- Me.Hide()
- frm.Show()
- Me.Close()
- End If
- End Sub
- Private Function ConnectToSQL() As Boolean
- Dim con As New SqlConnection
- Dim cmd As New SqlCommand
- Dim dbPassword As String
- Dim enteredPasswrd As String
- ' Dim userName As String
- Try
- con.ConnectionString = "Data Source "
- con.Open()
- cmd.Connection = con
- cmd.CommandText = " SELECT UserName, Password, extrainfo FROM users WHERE (UserName like '" & "%" & txtUsername.Text.ToLower() & "%" & "' )"
- Dim lrd As SqlDataReader = cmd.ExecuteReader()
- If lrd.HasRows Then
- While lrd.Read()
- 'Do something here
- dbPassword = lrd("Password").ToString()
- userName = lrd("UserName").ToString()
- extrainfo = lrd("assigned_ei").ToString()
- enteredPasswrd = txtPassword.Text()
- If dbPassword.Trim() = enteredPasswrd And userName.TrimEnd(vbCrLf.ToCharArray).ToLower() = txtUsername.Text.ToLower() Then
- Return True
- 'Clear all fields
- txtPassword.Text = ""
- txtUsername.Text = ""
- Else
- MsgBox("Incorrect Password")
- End If
- End While
- Else
- MessageBox.Show("Username and Password do not match..", "Authentication Failure", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
- 'Clear all fields
- txtPassword.Text = ""
- txtUsername.Text = ""
- End If
- Return False
- Catch ex As Exception
- MessageBox.Show("Error while connecting to SQL Server." & ex.Message)
- Finally
- con.Close() 'Whether there is error or not. Close the connection.
- End Try
- End Function
- Private Sub frmLogin_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- txtUsername.Focus()
- End Sub
- End Class
- Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- Dim con As New SqlConnection
- Dim cmd As New SqlCommand
- Try
- con.ConnectionString = "Data Source = location"
- con.Open()
- cmd.Connection = con
- cmd.CommandText = " SELECT * FROM table WHERE adduser = '" & user & "'"
- Dim lrd As SqlDataReader = cmd.ExecuteReader()
- If lrd.HasRows Then
- While lrd.Read()
- End While
- End If
- Catch ex As Exception
- MessageBox.Show("Error while connecting to SQL Server." & ex.Message)
- Finally
- con.Close() 'Whether there is error or not. Close the connection.
- End Try
- End Sub
Add Comment
Please, Sign In to add comment