表达式是一个值,因此不能成为赋值的目标 - asp.net

时间:2012-01-02 14:11:46

标签: asp.net

我收到了上述错误。它是在开发模式下工作,但不是现场,任何想法?

当我将它们写入文本文件时,读者中有适当的值....

        Do While reader.Read()
            personList.Add(New Person() With {.ID = reader("user_id"), .Name = reader("person")})
        Loop

谢谢,

Public Class Person
Private m_ID As Integer
Public Property ID() As Integer
    Get
        Return m_ID
    End Get
    Set(ByVal value As Integer)
        m_ID = value
    End Set
End Property
Private m_Name As String
Public Property Name() As String
    Get
        Return m_Name
    End Get
    Set(ByVal value As String)
        m_Name = value
    End Set
End Property

1 个答案:

答案 0 :(得分:0)

现在排序,只是做了不同的方式。得到了新的构造函数来获取参数并以这种方式设置它们。把它们作为可选项,在其他地方调用的构造和不需要的参数。

Public Sub New(Optional ByVal uid As Integer = 0, Optional ByVal uname As String = "")
    ID = uid
    Name = uname
End Sub


Dim uid As Integer
Dim uname As String
Do While reader.Read()
   uid = reader("user_id")
   uname = reader("person")
   personList.Add(New Person(uid, uname))
Loop