开发者

How can I bind an entity Data Source to the results of a query

开发者 https://www.devze.com 2023-01-19 05:07 出处:网络
I have a query that will go away an and find data Dim HSNs As String = String.Join(\",\", ListOfHSNs.Cast(Of String)().ToArray())

I have a query that will go away an and find data

 Dim HSNs As String = String.Join(",", ListOfHSNs.Cast(Of String)().ToArray())



        Dim query As String = "SELECT VALUE O FROM v_BillData AS O WHERE O.HSNumber IN {'" & HSNs & "'}"



        Dim hs As New ObjectQuery(Of v_BillData)(query, CType(Session("ObjectCon"), ObjectContext))
开发者_Python百科

what I now wish to do is to use the results of this query to databind to a EntityDataSource How can I do this?


You can try to use the Selecting EntityDataSource event like in the following example:


Protected Sub EntityDataSource1_Selecting(ByVal sender As Object, ByVal e As EntityDataSourceSelectingEventArgs)
  Dim HSNs As String = String.Join(",", ListOfHSNs.Cast(Of String)().ToArray())
  Dim query As String = "SELECT VALUE O FROM v_BillData AS O WHERE O.HSNumber IN {'" & HSNs & "'}"
  Dim source As EntityDataSource = Nothing
  source = TryCast(Me.Page.FindControl("EntityDataSource1"),EntityDataSource)
  If (Not source Is Nothing) Then
    source.EntitySetName = Nothing
    source.CommandText = query
  End If
End Sub

You should set EntitySetName to Nothing because it will throw an error if you have setup EntityDataSource before.

0

精彩评论

暂无评论...
验证码 换一张
取 消