Rss & SiteMap

Foxtable(狐表) http://www.foxtable.com

新一代数据库软件,完美融合Access、Foxpro、Excel、vb.net之优势,人人都能掌握的快速软件开发工具!
共4 条记录, 每页显示 10 条, 页签: [1]
[浏览完整版]

标题:[求助]创建类

1楼
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, "宋江")

报错了,提示:至少一个参数没有被指定值

是哪里写得不对吗?
2楼
puma 发表于:2024/4/12 8:11:00
Dim userAccount As New UserAccount(connectionString, "宋江")   可以这么写吗?



我都是这么写
Dim userAccount As New UserAccount
userAccount.New(connectionString, "宋江")
3楼
有点蓝 发表于: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
4楼
chnfo 发表于:2024/4/12 8:49:00
OK,我知了
共4 条记录, 每页显示 10 条, 页签: [1]

Copyright © 2000 - 2018 foxtable.com Tel: 4000-810-820 粤ICP备11091905号

Powered By Dvbbs Version 8.3.0
Processed in .03906 s, 2 queries.