Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.
Object Reference not set to an instance of an object
I'm trying to do a login form where userid and password will match the respective textboxes and so that I can go to another form. Here is the code that I used for VB.NET. I know the VB6 code but don't know VB.NET. Here is the code:
Private Sub LoginButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnlogin.Click
'Create a Command Object
Dim objCommand As OleDbCommand
Dim objCommand2 As OleDbCommand
'Call user and password
OleDbDataAdapter1.SelectCommand.Parameters("UserId").Value = UserText.Text & "%"
OleDbDataAdapter1.SelectCommand.Parameters("password").Value = PasswordText.Text & "%"
// This part is highlighted and "Object Reference not set to an instance of an object" pops up as error
If objCommand.Parameters("@UserID").Value = UserText.Text And
objCommand2.Parameters("@password").Value = PasswordText.Text Then
Dim mainfrm As New Form()
MsgBox("Your Password or Username is incorrect. Please try Again")
The Connection and CommandText I'm using the objects to do.
Can anyone please help me with this? Thanks a lot! I really need the help.
If there is any better way to write a login page, please email me and teach me if you can. I'll really appreciate the help. Thanks
0 · ·