BC30068:表达式是一个值,因此不能作为赋值的目标

时间:2012-01-02 07:30:15

标签: asp.net

将一些代码从开发服务器转移到实时服务器时,我遇到了问题。

它在Dev中工作但不在Live ..

此处发生错误:

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

并且错误消息是:Expression是一个值,因此不能作为赋值的目标。

代码背后:

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

结束班

有什么想法吗?

谢谢,

1 个答案:

答案 0 :(得分:0)

决定采用不同的方式

        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