我遇到错误:引用非共享成员需要对象引用
试图在VB.net中传递对象
在TBS000.Update(U)行上发生错误。
我对此很陌生,我在做什么错了?
Public Class Login
Private Sub BtnLogIn_Click(sender As Object, e As EventArgs) Handles BtnLogIn.Click
Dim U As Object
U = New User(txtUser.ToString, txtPass.ToString)
TBS000.Update(U)
End Sub
End Class
Public Class TBS000
Dim Con As SqlConnection = New SqlConnection
Public Function Update(User As Object) As String
Con = ConnectDB()
.
.
.
Public Class User
Private _userID As String
Private _password As String
Public Sub New(ByVal U As String, ByVal P As String)
UserID = U
Password = P
End Sub
Public Property UserID As String
Get
Return _userID
End Get
Set(value As String)
_userID = value
End Set
End Property
Public Property Password As String
Get
Return _password
End Get
Set(value As String)
_password = value
End Set
End Property
End Class
答案 0 :(得分:0)
在代码中回顾@jmcilhinney的注释
Public Class Login
Private Sub BtnLogIn_Click(sender As Object, e As EventArgs) Handles BtnLogIn.Click
Dim U As New User(txtUser.ToString, txtPass.ToString)
Dim TBS As New TBS000()
Dim RetVal As String = TBS.Update(U)
End Sub
End Class
Public Class TBS000
Public Function Update(U As User) As String
Dim s As String = ""
Using Con As New SqlConnection("Your connection string")
End Using
Return s
End Function
End Class
Public Class User
Public Sub New(ByVal U As String, ByVal P As String)
UserID = U
Password = P
End Sub
Public Property UserID As String
Public Property Password As String
End Class