Link to home
Start Free TrialLog in
Avatar of Natchiket
NatchiketFlag for United Kingdom of Great Britain and Northern Ireland

asked on

BC30311: Value of type 'System.Collections.ArrayList' cannot be converted to '1-dimensional array of ContactDetails'.

Hi ASP.noob here .... So I'm using this expensive book (ASP.NET 2.0 Moroney & MacDonald) to try and learn ASP.NET and in the code below I'm following the book examples to try and build the database abstraction layer... only trouble is I can't get it to work & neither can the ASP.NET compiler...

The error occurs on the line

Return alC



ports Microsoft.VisualBasic

Public Class ContactDetails

    Dim lngID As Integer
    Dim strFN, strLN As String

    Public Property ID() As Integer
        Get
            Return lngID
        End Get
        Set(ByVal value As Integer)
            lngID = value
        End Set
    End Property

    Public Property FirstName() As String
        Get
            Return strFN
        End Get
        Set(ByVal value As String)
            strFN = value
        End Set
    End Property

    Public Property LastName() As String
        Get
            Return strLN
        End Get
        Set(ByVal value As String)
            strLN = value
        End Set
    End Property


    Public Sub New(ByVal intID As Integer, ByVal strFN As String, ByVal strLN As String)
        Me.ID = intID
        Me.FirstName = strFN
        Me.LastName = strLN
    End Sub
End Class

Public Class SESDB
    Dim strCS As String   'Connection string
    Dim strSC As String   'Search Criteria

    Public Property SearchCriteria() As String
        Get
            SearchCriteria = strSC
        End Get
        Set(ByVal value As String)
            strSC = value
        End Set
    End Property


    Public Function SearchContacts() As ContactDetails()
        Dim cnn As New Data.OleDb.OleDbConnection(strCS)
        Dim cmd As New Data.OleDb.OleDbCommand

        Dim strSQL As String
        Dim alC As New ArrayList

        Try
            strSQL = "SELECT cID,FirstName,LastName FROM tblContacts WHERE LastName='" & strCS & "'"
            cnn.Open()
            cmd.CommandType = Data.CommandType.Text
            cmd.CommandText = strSQL

            Dim rdr As Data.OleDb.OleDbDataReader = cmd.ExecuteReader()
            Do While rdr.Read
                Dim cntct As New ContactDetails( _
                CInt(rdr("cID")), _
                CStr(rdr("FirstName")), _
                CStr(rdr("LastName")))
                alC.Add(cntct)
            Loop
            rdr.Close()
            Return alC  <----- Error here!





        Catch ex As Exception
            Throw New ApplicationException("Data Error")

        Finally
            cnn.Close()

        End Try







    End Function

    Public Sub New()
        strCS = System.Web.Configuration.WebConfigurationManager.ConnectionStrings("SES").ConnectionString
    End Sub
End Class
ASKER CERTIFIED SOLUTION
Avatar of KarinLoos
KarinLoos

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Natchiket

ASKER

Thanks Karin .... guess I should have spotted that lol