Trouble with Simple Login Form

ReportsNerd

Active member
Joined
Nov 24, 2012
Messages
31
Programming Experience
3-5
Hi Im creating a simple login form in VS 2010 with MS Access, but getting errors: Reference to a non-shared member requires an object reference. How do I correct this and maybe avoid in the future?

Code:
Imports WindowsApplication1.DTdatasetTableAdapters

Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
If Not SECURITYTableAdapter.Login(TextBox1.Text, TextBox2.Text) = Nothing Then
Then MsgBox ("Loged In!")
End If
End Sub
End Class

Thank you


 
Hi,

It sounds like you have declared a variable at the class level within your DTdatasetTableAdapters class and then you are trying to access that variable within other sub classes of this parent class. If you have, then you need to declare your variable as:-

VB.NET:
Private Shared <VariableName> as <VariableType>

Here is an example of what would cause this error:-

VB.NET:
Public Class Class1
  Private myVariable As String = "This is a test"
 
  Public Class myClassName
    Public Property myProperty As String = myVariable
  End Class
End Class

Here is an example of what would work:-

VB.NET:
Public Class Class2
  Private Shared myVariable As String = "This is a test"
 
  Public Class myClassName
    Public Property myProperty As String = myVariable
  End Class
End Class

Hope that helps.

Cheers,

Ian
 
Hi Ian, that makes sense, however, I found out what I was doing wrong. I forgot to add the table adapter to my form after I created it. The table adapter I created was located in the Tootbox under the components section. My code that works now looks like this:
Imports WindowsApplication1.DTdatasetTableAdapters

Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
If Not SecurityTableAdapter1.Login(TextBox1.Text, TextBox2.Text) = Nothing Then
MsgBox("Loged In!")
End If
End Sub
End Class

Thanks!
 
Back
Top