I am trying to bind some values to an ASP.NET Chart control. This is my code so far:
Dim xValues As String() = {"Option1", "Option2", "Option3", "Option4"}
chartControl.Series(0).Points.DataBindXY(xValues, valuesAl)
valuesAl is an ArrayList. The code to add the values to the ArrayList is as follows:
Dim cmd As New SqlCommand("StoredProcedure", Conn)
cmd.CommandType = CommandType.StoredProcedure
Dim valuesAl As New ArrayList
Dim r As SqlDataReader = cmd.ExecuteReader
While r.Read()
valuesAl.Add(r("Value"))
End While
r.Close()
However, I am getting the following error: Enumeration already finished
Am I binding the values from the database to the Chart control correctly and if so why am I getting this error message?
Many thanks in advance for your help!
You need to make sure that your
valuesA1ArrayList ends up with the same number of values as you have in yourxValuesarray. Internally it’s looping through both collections, expecting them to have the same number, and you are getting an error because you have fewer members in the valuesA1 ArrayList.