Unable to cast object of type 'System.Int32' to type 'System.Collections.IEnumerable'

Posted on 2011-05-12
Last Modified: 2012-05-11
trying to set up a pie chart of an application but I keep getting this error, the data that comes from the db are numbers.  what am I doing wrong here.

Unable to cast object of type 'System.Int32' to type 'System.Collections.IEnumerable'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Unable to cast object of type 'System.Int32' to type 'System.Collections.IEnumerable'.

Source Error:

Line 66:
Line 67:
Line 68:         chInOut.Series(0).Points.DataBindXY("Scheduled", myDataTable.Rows(0)(0))
Line 69:         chInOut.Series(1).Points.DataBindXY("Check-In", myDataTable.Rows(0)(1))
Line 70:         chInOut.Series(2).Points.DataBindXY("Not Present", myDataTable.Rows(0)(0) - myDataTable.Rows(0)(1))

Private Sub FillPieCharts()
        Dim EventId As Integer = ddlSRPMonth.SelectedValue
        Dim SRpDay As String = ddlSRPDay.SelectedValue

        sql = "Select COUNT(intScheduleID), (Select COUNT(intSrpAttendId) from tblSRPAttendance where intEventId = " & EventId & ") from ModreScheduler.dbo.tblSchedule as s INNER JOIN ModreScheduler.dbo.tblTimeSlots as " _
            & "ts on ts.intTimeSlotID = s.intTimeSlotID where intEventDateID = " & SRpDay

        myDataTable = New DataTable
        myDataTable = getData(sql)

        chInOut.Series(0).Points.DataBindXY("Scheduled", myDataTable.Rows(0)(0))
        chInOut.Series(1).Points.DataBindXY("Check-In", myDataTable.Rows(0)(1))
        chInOut.Series(2).Points.DataBindXY("Not Present", myDataTable.Rows(0)(0) - myDataTable.Rows(0)(1))

        pnlView.Visible = True
    End Sub

Open in new window

Question by:kdeutsch
    LVL 14

    Accepted Solution

    The DataBindXY() method expects IEnumerable parameters, not a single item (in your case, you are passing an integer). The method expects 'several' integers, whereas you are passing one integer.

    Look at the example below:

    ' Initialize an array of doubles
    Dim yval As Double() = {2, 6, 4, 5, 3}
    ' Initialize an array of string
    Dim xval As String() = {"Peter", "Andrew", "Julie", "Mary", "Dave"}
    ' Bind the double array to the Y axis points of the Default data series
    Chart1.Series("Series 1").Points.DataBindXY(xval, yval)

    Open in new window

    LVL 21

    Expert Comment

    Try this:

    chInOut.Series(0).Points.DataBindXY("Scheduled", CType(myDataTable.Rows(0)(0),Integer))


    chInOut.Series(0).Points.DataBindXY("Scheduled", CInt(myDataTable.Rows(0)(0)))


    chInOut.Series(0).Points.DataBindXY("Scheduled", Integer.Parse(myDataTable.Rows(0)(0)))

    LVL 21

    Expert Comment

    Oops.  Ignore my previous post, I didn't realise it was casting a single item where it needs a collection and not a single item.  My bad. :-)

    Author Comment


    I am trying to make a simple pie chart that has 3 sections, one for scheduled, one for checked in, one for not present, the numbers for each of these comes from mydatatable.  how can I do this.
    LVL 83

    Expert Comment


    Author Closing Comment

    ok see what I was doing wrong.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now