Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

VB6 to VB.NET convert - HELP

timmy334timmy334 Member Posts: 16
Here is the code for a login form that I have in a VB6 app that I'm writing for a friend. I'm still a "newbie" that's 23 and still in college for a BS in Software Development, so bear with me. The biggest problem I'm having so far is trying to hard code SQL statements in ADO.NET and setting up the connection strictly via code, well, you will see below. I have found NO documentation on how to do this type of simple connection to a database, opening, using SQL, and closing the database like below strictly using code and not the wizards or gui. I would like to do this in VB.NET the first time so I don't have to take this VB6 code and rewrite it for .NET. But I'll use VB6 if it gets me his payment faster, hehehe. Thanks in advance for any help!
***************************************
'This is making the connection to the database
Dim dbcon As Connection
Dim i As Integer 'declare i to count the wrong passwords
Dim rs As New Recordset

Private Sub cmdLogin_Click()
Dim hello As String
If i > 1 Then 'checks to see fi i is lass than 3
rs.Open "SELECT Login, Password, FirstName FROM Employee WHERE Login='" & txtLogin.Text & "' AND Password='" & txtPassword.Text & "'", dbcon, adOpenKeyset, adLockOptimistic
If rs.RecordCount = 0 Then
MsgBox "Invalid login and password", vbCritical, "Login Failure"
Else
hello = rs("FirstName")
MsgBox "Greetings, " & hello & "", vbInformation, "Welcome!"
frmMain.Show
frmLogin.Hide
End If
rs.Close
i = i - 1
Else
MsgBox "Invalid login and password. InvEst is closing.", vbCritical, "Closing"
End
End If
End Sub

Private Sub cmdLoginExit_Click()
End
End Sub
Private Sub Form_Load()

End Sub
Private Sub Form_Initialize()
i = 3 'This allows for 3 wrong passwords
Set dbcon = New Connection 'creates instance of connection
dbcon.Open "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = " & App.Path & "InvEst.mdb"
End Sub

Private Sub txtLogin_KeyPress(KeyAscii As Integer)
'The first two lines of code check to see if the user is using CTRL + C, CTRL + V, or CTRL + X
'if so, it enters nothing
If KeyAscii = 3 Or KeyAscii = 22 Or KeyAscii = 24 Then
KeyAscii = 0
ElseIf KeyAscii = 13 Then
KeyAscii = 0
Else
KeyAscii = Asc(UCase(Chr(KeyAscii))) 'Changes entered text to uppercase
End If
End Sub

Private Sub txtPassword_KeyPress(KeyAscii As Integer)
'The first two lines of code check to see if the user is using CTRL + C, CTRL + V, or CTRL + X
'if so, it enters nothing
If KeyAscii = 3 Or KeyAscii = 22 Or KeyAscii = 24 Then
KeyAscii = 0
ElseIf KeyAscii = 13 Then
KeyAscii = 0
Call cmdLoginExit_Click
Else
KeyAscii = Asc(UCase(Chr(KeyAscii))) 'Changes entered text to uppercase
End If
End Sub

Sign In or Register to comment.