从代码背后构建实体数据源控件

时间:2012-12-01 12:27:43

标签: entitydatasource

如果我在我的aspx中有一个entitydatasource控件(看起来像这样 并由设计器中的配置向导创建并工作)

<asp:EntityDataSource ID="edsFuelPrices" runat="server"
                        ConnectionString="name=enerEntities" DefaultContainerName="enerEntities"
                        EnableFlattening="False" EntitySetName="dieselprices" Select="it.[date], it.[NYMarineDiesel]">
                </asp:EntityDataSource>

我想在后面的代码中构建它并从aspx标记中删除所有属性。 为什么以下不起作用?我在加载时遇到错误“查询语法无效。附近转义标识符'[NYMarineDiesel]',第1行,第21列”即使NYMarineDiesel是表中的有效列

Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
    If Not Page.IsPostBack Then
        ' when page loads for the first time just show the Marine diesel prices
        Try
            edsFuelPrices.ConnectionString = "name=enerteckEntities"
            edsFuelPrices.DefaultContainerName = "enerteckEntities"
            edsFuelPrices.EnableFlattening = False
            edsFuelPrices.EntitySetName = "dieselprices"
            'edsFuelPrices.Include = "Date,NYMarineDiesel"
            edsFuelPrices.Select = "it.[Date], it[NYMarineDiesel]"
        Catch ex As Exception
            MsgBox("An error occurred while loading this page: " & ex.Message.ToString())
        End Try
    Else
        'need to add the code on postbacks, the data returned for the chart is  determined by what checkboxes are checked in the checkboxlist

    End If
                'FormatXAxisLabels(chtFuelPrices, "MainChartArea", 9)
                FormatYAxisLabels(chtFuelPrices, "MainChartArea", 9)
                FormatLineCharts(chtFuelPrices, True, "MainLegend", "Fuel Types")
End Sub

1 个答案:

答案 0 :(得分:0)

您是否错过了'it'和属性名称之间的点? - 你有it[NYMarineDiesel],我相信你应该有it.[NYMarineDiesel]"