以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- [求助]创建类 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=191342) |
-- 作者:chnfo -- 发布时间:2024/4/11 23:29:00 -- [求助]创建类 准备创建一个类,获取用户的一些属性。 在全局代码中这样写: 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, "宋江") 报错了,提示:至少一个参数没有被指定值 是哪里写得不对吗? |
-- 作者:puma -- 发布时间:2024/4/12 8:11:00 -- Dim userAccount As New UserAccount(connectionString, "宋江") 可以这么写吗? 我都是这么写 Dim userAccount As New UserAccount userAccount.New(connectionString, "宋江")
|
-- 作者:有点蓝 -- 发布时间:2024/4/12 8:31:00 -- cmd.CommandText = "SEL*ECT Email, IsActive FROM {TbUser} WHERE Username = \'" & username & "\'" 如果要使用参数化的用法,参考这种:http://www.foxtable.com/webhelp/topics/3266.htm
|
-- 作者:chnfo -- 发布时间:2024/4/12 8:49:00 -- OK,我知了 |