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

Natchiket
Natchiket used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Problem is reasonably simple
"Public Function SearchContacts() As ContactDetails() "
your function is declared to return an object of type ContactDetails
and you are returning an arraylist.
Change to
Public Function SearchContacts() As ArraylLst()

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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial