Hey guys!
Im working on a login form that connects to an SQL 2008 database. i have created records in the table for users who can login. i however want a code snippet that matches the username and password entered with the records in the database. i have a rough idea about it but
this is what i have:
conn - the connection string to the database
usercmd - object for executing sql commands
userstring - the sql string object
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
Dim count As Integer
Try
If conn.State = ConnectionState.Closed Then
conn.Open()
Else
conn.Open()
userstring = "Select * from Hotel.dbo.Users where UserName = '" & UsernameTextBox.Text & "' and Password = '" & PasswordTextBox.Text & "'"
usercmd = New SqlCommand(userstring, conn)
count = usercmd.ExecuteScalar
If count > 0 Then
MsgBox("records exist")
form2.show()
'load main form of application
Else
MsgBox("no records found")
're-enter login username and password
End If
conn.Close()
End If
Catch ex As Exception
Throw ex
conn.Close()
End Try
End Sub
Some input on how i can correct this and get it working