[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2011-05-12
6
Medium Priority
?
1,839 Views
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

0
Comment
Question by:kdeutsch
6 Comments
 
LVL 14

Accepted Solution

by:
robasta earned 1600 total points
ID: 35747331
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



0
 
LVL 21

Expert Comment

by:Alfred A.
ID: 35747334
Try this:

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

Or

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

Or

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

0
 
LVL 21

Expert Comment

by:Alfred A.
ID: 35747365
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. :-)
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 

Author Comment

by:kdeutsch
ID: 35747889
All,

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.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 35748915
0
 

Author Closing Comment

by:kdeutsch
ID: 35841647
ok see what I was doing wrong.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month18 days, 5 hours left to enroll

831 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