如果我的 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 是表中的有效列,我在加载时收到错误“查询语法无效。接近转义标识符 '[NYMarineDiesel]',第 1 行,第 21 列”
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