New Posts New Posts RSS Feed: How do I get the results of query into observable collection?
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

How do I get the results of query into observable collection?

 Post Reply Post Reply
Author
Terry Wells View Drop Down
Newbie
Newbie


Joined: 14-Feb-2011
Posts: 8
Post Options Post Options   Quote Terry Wells Quote  Post ReplyReply Direct Link To This Post Topic: How do I get the results of query into observable collection?
    Posted: 21-Apr-2011 at 5:26am
Hello All,
 
Really simple I'm sure but I'm trying to get my query into an observable collection within a VB WinForms app?
 
 Dim mgr As New OperaEntities()
 Dim myCompanyHistory As New ObservableCollection(Of tblCompanyHistory)
 Dim qry = From comphist In mgr.tblCompanyHistories Where comphist.CREF = 11414
           Select comphist
               
     mgr.ExecuteQuery(qry) <---I can't figure out the syntax here to push the results into the MyCompanyHistory collection
     Me.RadGridView1.DataSource = myCompanyHistory
 
Any pointers? Is this the correct methodolgy to use?
 
Many thanks
 
Terry
 
Back to Top
smi-mark View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 24-Feb-2009
Location: Dallas, Texas
Posts: 343
Post Options Post Options   Quote smi-mark Quote  Post ReplyReply Direct Link To This Post Posted: 21-Apr-2011 at 8:16am
Hi Terry,

You can do it a few ways, here are a couple examples:

Dim mgr As New OperaEntities()
Dim myCompanyHistory As ObservableCollection(Of tblCompanyHistory)
Dim qry = From comphist In mgr.tblCompanyHistories Where comphist.CREF = 11414 Select comphist               
dim results = mgr.ExecuteQuery(qry)

myCompanyHistory  = new ObservableCollection(Of tblCompanyHistory)(results)
Me.RadGridView1.DataSource = myCompanyHistory

Dim mgr As New OperaEntities()
Dim myCompanyHistory As new ObservableCollection(Of tblCompanyHistory)
Dim qry = From comphist In mgr.tblCompanyHistories Where comphist.CREF = 11414 Select comphist               
dim results = mgr.ExecuteQuery(qry)

results.ForEach(function (r) myCompanyHistory.Add(r))  <-- I think this is the VB.Net syntax for in. in C# we simply do results.ForEach(myCompanyHistory.Add);
Me.RadGridView1.DataSource = myCompanyHistory
Back to Top
Terry Wells View Drop Down
Newbie
Newbie


Joined: 14-Feb-2011
Posts: 8
Post Options Post Options   Quote Terry Wells Quote  Post ReplyReply Direct Link To This Post Posted: 21-Apr-2011 at 8:48am
Thanks for that,
 
Your first option doesn't quite work I get "Overload resoltion failed because no accessible 'New' can be called without a narrowing converision" on line myCompanyHistory = New ObservableCollection(Of tblCompanyHistory)(results)
 
However your second option gave me the answer I was looking for although
results.ForEach(function (r) myCompanyHistory.Add(r)) doesnt work,
 
but I did it the long way round with
 
For Each r In results
        myCompanyHistory.Add(r)
Next
 
Thanks again Mark
 
Regards
 
Terry
 
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down