类型的值...无法转换为

时间:2014-05-03 18:58:11

标签: asp.net vb.net

每当我尝试运行代码时,我都会收到以下错误。有什么可能导致我无法转换的建议吗?似乎两种类型都是相同的,所以我对这一点感到有些困惑。

Value of type 'System.Collections.Generic.List(Of CVE)' cannot be converted to 'System.Collections.Generic.List(Of CVE)'

此处发生错误:

Dim cveList As List(Of CVE)
cveList = CVERepository.GetInstance.ReadAllCVEs

这是CVERepository类:

Public Class CVERepository

Private Sub New()

End Sub

Public Shared ReadOnly Property GetInstance As CVERepository
    Get
        Static Instance As CVERepository = New CVERepository
        Return Instance
    End Get
End Property

Public Function ReadAllCVEs() As List(Of CVE)
    Dim objAdapter As OleDb.OleDbDataAdapter
    Dim dtCVE As New DataTable()
    Dim strSQL As String
    Dim strConn As String
    Dim dvCVE As DataView

    strConn = ConnectStringBuild()
    strSQL = "Select * From CVE"

    objAdapter = New OleDb.OleDbDataAdapter(strSQL, strConn)
    objAdapter.Fill(dtCVE)
    dvCVE = dtCVE.DefaultView
    Dim cveList As New List(Of CVE)

    'Put it into an object list to make it more managable.
    For index = 0 To dvCVE.Count - 1
        Dim cve As New CVE
        cve.ID = dvCVE(index)("CVEID")
        cve.PublishedDate = dvCVE(index)("PublishedDate")
        cve.Availability = dvCVE(index)("Availability")
        cve.CVSSScore = dvCVE(index)("CVSSScore")
        cve.Confidentiality = dvCVE(index)("Confidentiality")
        cve.Integrity = dvCVE(index)("Integrity")
        cve.Summary = dvCVE(index)("Summary")
        cveList.Add(cve)
    Next

    Return cveList

End Function

Public Shared Function ConnectStringBuild() As String
    'Grabbing connection string from web.config
    Return System.Configuration.ConfigurationManager.ConnectionStrings("CVEConnectionString").ConnectionString
End Function

End Class

有关错误的任何建议吗?

1 个答案:

答案 0 :(得分:0)

稍微改变一下

Dim cveList As List(Of CVE)
cveList.AddRange(CVERepository.GetInstance.ReadAllCVEs)