本文介绍了绑定的DataReader ASP图表控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我有一个DataReader,在理论上将调用StoredProcedure时,并绑定返回给一个图表查询。

Essentially I have a datareader that in theory will call a storedprocedure, and bind the query that is returned to a chart.

这是我想绑定到一个图表的数据:

This is the data that I'd like to be bound to a chart:

ForecastDesc    Previous    Current Budget  Forecast 4  Forecast 7
Period1 966025.79   1466872.95  1000000.00  0.00    0.00
Period2 1051175.09  1489785.15  1000000.00  0.00    0.00
Period3 1205352.26  1552806.49  1000000.00  0.00    0.00
Period4 1261483.84  1544562.06  1000000.00  50.00   0.00
Period5 1298918.58  1681396.55  1000000.00  45.00   0.00
Period6 1314396.68  1611695.58  10000000.00 50.50   0.00
Period7 1465150.48  1622354.24  1000000.00  50.50   123.00
Period8 1426084.73  1632609.46  1000000.00  50.50   0.00
Period9 1395144.09  370334.88   1000000.00  50.50   0.00
Period10    1347280.57  0.00    1000000.00  50.50   0.00
Period11    1374741.53  0.00    1000000.00  50.50   0.00
Period12    1331704.11  0.00    1000000.00  50.20   0.00
Period13    1367272.27  0.00    1000000.00  50.70   0.00

我的VB code是如下:

My vb code is as follows:

    Protected Sub YearList_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles YearList.SelectedIndexChanged

    Chart1.Visible = True

    mySqlConn = New SqlConnection
    mySqlConn.ConnectionString = "Server=" + dbServerName + "; Database=" + dbCatalogName + "; Trusted_Connection=True;"


    pSql = New SqlCommand

    pSql.Connection = mySqlConn
    pSql.CommandType = CommandType.StoredProcedure
    pSql.CommandText = "dbo.[sp_DW_Transpose_BudgetForecast]"


    pSql.Parameters.Add("@seg1", SqlDbType.NVarChar)
    pSql.Parameters.Add("@seg2", SqlDbType.NVarChar)
    pSql.Parameters.Add("@seg3", SqlDbType.NVarChar)
    pSql.Parameters.Add("@year", SqlDbType.NVarChar)

    pSql.Parameters("@seg1").Value = Seg1.SelectedItem.Text
    pSql.Parameters("@seg2").Value = Seg2.SelectedItem.Text
    pSql.Parameters("@seg3").Value = Seg3.SelectedItem.Text
    pSql.Parameters("@year").Value = YearList.SelectedItem.Text

    pSql.Connection.Open()
    pReader = pSql.ExecuteReader(CommandBehavior.CloseConnection)

    While pReader.Read()
        Chart1.DataBindTable(pReader)
    End While

    pReader.Close()
    pReader = Nothing

    mySqlConn.Close()



End Sub

在我的web程序获取到它已准备好创建图表我碰到下面的错误点:

When my web program gets to the point where it is ready to create the chart I get the following error:

Server Error in '/' Application.

Specified method is not supported.

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.NotSupportedException: Specified method is not supported.

Source Error:


Line 111:
Line 112:        While pReader.Read()
Line 113:            Chart1.DataBindTable(pReader)
Line 114:        End While
Line 115:


Stack Trace:


[NotSupportedException: Specified method is not supported.]
 System.Data.Common.DbEnumerator.Reset() +65
 System.Web.UI.DataVisualization.Charting.ChartImage.GetDataSourceMemberNames(Object     dataSource, Boolean usedForYValue) +2363
 System.Web.UI.DataVisualization.Charting.ChartImage.DataBindTable(IEnumerable dataSource, String xField) +59
 System.Web.UI.DataVisualization.Charting.Chart.DataBindTable(IEnumerable dataSource) +36
 Forecasting.WebForm1.YearList_SelectedIndexChanged(Object sender, EventArgs e) in
 System.Web.UI.WebControls.ListControl.OnSelectedIndexChanged(EventArgs e) +113
 System.Web.UI.WebControls.DropDownList.RaisePostDataChangedEvent() +143
     System.Web.UI.WebControls.DropDownList.System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent() +10
 System.Web.UI.Page.RaiseChangedEvents() +135
 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean    includeStagesAfterAsyncPoint) +4867

 Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET    Version:4.0.30319.1

反正林不知道,如果是Databindtable正确的方法,我应该使用或者甚至Databindcrosstable。我在这个问题再过4天未被盯着根据你的专业知识我打电话,希望能够引导我正确的方向了。

Anyways Im not sure if Databindtable is the correct method I should be using or maybe even Databindcrosstable. I've been staring at this problem for four days now and am calling upon your expertise to hopefully guide me in the correct direction now.

推荐答案

我认为这个问题是您正在呼叫 .DataBindTable(),并通过在的DataReader ,但DataReader的确实的的工具的IEnumerable ,因此不被支持有关该方法的错误。尝试将数据转储到数据表的DataSet 并传递作为参数传递给 .DataBindTable ()

I believe the problem is you are calling .DataBindTable() and passing in a DataReader, but DataReader does not implement IEnumerable and therefore the error about the method not being supported. Try dumping the data into a DataTable or DataSet and pass that as the parameter to .DataBindTable()

这篇关于绑定的DataReader ASP图表控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-26 22:36
查看更多