如果我的ASPX中有一个实体数据源控件(看起来像这样并由设计器中的配置向导创建并工作)
<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
你不是在"it"和属性名称之间缺少一个点吗? - 你有it[NYMarineDiesel]
,我相信你应该有it.[NYMarineDiesel]"