准备创建一个类,获取用户的一些属性。在全局代码中这样写:
Public Class UserAccount
Public Username As String
Public Email As String
Public IsActive As Boolean
Public Sub New(connectionString As String, username As String)
Dim cmd As New SQLCommand
cmd.ConnectionName = connectionString
cmd.CommandText = "SEL*ECT Email, IsActive FROM {TbUser} WHERE Username = @username"
Dim Values = cmd.ExecuteValues
If Values.Count > 0 Then
Me.Username = username
Me.Email = Values("Email")
Me.IsActive = Values("IsActive")
End If
End Sub
End Class
然后在命令窗口执行
Dim connectionString As String = "XX"
Dim userAccount As New UserAccount(connectionString, "宋江")
报错了,提示:至少一个参数没有被指定值
是哪里写得不对吗?
Dim userAccount As New UserAccount(connectionString, "宋江") 可以这么写吗?
我都是这么写
Dim userAccount As New UserAccount
userAccount.New(connectionString, "宋江")