JavaEar 专注于收集分享传播有价值的技术资料

BC30068: Expression is a value and therefore cannot be the target of an assignment

I've ran into a problem when transfering some code from dev server to live server.

It is working in Dev but not on Live..

The error occurs here:

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

and the error message is: Expression is a value and therefore cannot be the target of an assignment.

Code behind:

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

Public Sub New()
End Sub

Public Function GetPersonList(ByVal tryvalue As String, ByVal is_cust As Integer) As List(Of Person)

    Dim personList As New List(Of Person)()

    Dim sqlCommand As New SqlCommand()
    Dim connectionString As String = ConfigurationManager.ConnectionStrings("scConnString").ConnectionString
    Dim command As New SqlCommand
    Dim reader As SqlDataReader
    Dim org_id = HttpContext.Current.Session("org_id")
    Dim strName As String = ""
    Dim nID As Integer = 0

    Dim loadNameSQL As String = "SELECT distinct top 10 user_id, firstname + ' ' + lastname as person FROM users  WHERE " & _
   "firstname + ' ' + lastname like @tryvalue and org_id = @org_id and delete_flag=0"

    sqlCommand.Parameters.AddWithValue("tryValue", tryvalue + "%")
    sqlCommand.Parameters.AddWithValue("org_id", org_id)

    Dim sqlConnection As New SqlConnection(connectionString)

    Try
        sqlConnection.Open()
        sqlCommand.CommandText = loadNameSQL
        sqlCommand.Connection = sqlConnection
        reader = sqlCommand.ExecuteReader()

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

    Finally
        sqlConnection.Close()
    End Try

    Return personList
End Function

End Class

Any ideas?

Thanks,

1个回答

    最佳答案
  1. Decided to do this differently

            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
    
    Public Sub New(Optional ByVal uid As Integer = 0, Optional ByVal uname As String = "")
        ID = uid
        Name = uname
    End Sub