-2

我正在尝试创建一个具有某些属性的功能类,但它一直在说

你调用的对象是空的。

Public Class Class1    
    Private sParam As Dictionary(Of String, String)

    Public Property param As Dictionary(Of String, String)
        Set(ByVal value As Dictionary(Of String, String))
            sParam = value
        End Set
        Get
            Return sParam
        End Get
    End Property

    Public Sub insert(ByVal table As String)
        Dim col As String = ""
        Dim val As String = ""
        Dim init As Integer = 0

        For Each x In param
            If init = 0 Then
                col &= x.Key
                val &= x.Value
                init = 1
            Else
                col &= ", " & x.Key
                val &= ", " & x.Value
            End If
        Next

        MsgBox("INSERT INTO " & table & "(" & col & ") VALUES (" & val & ")")
    End Sub
End Class
Public Class Form1
    Private Sub Button1_Click(ByVal sender As Button, ByVal e As System.EventArgs) Handles Button1.Click
        Dim db As Class1
        db = New Class1
        db.param.Add("First_name", "John")
        db.param.Add("Last_name", "Doe")
        db.insert("tblUsers")
    End Sub
End Class
4

1 回答 1

0

您需要实例化您的Dictionary(Of String, String)对象:

Public Class Class1    
    Private sParam As New Dictionary(Of String, String)
                      '''
    ...

End Class
于 2019-04-28T10:28:40.880 回答