This is probably going to be an easy answer, but I can't find it anywhere. I want to assign a labels .text property to a field returned in a LINQ Query: Dim db As New ClientDataContext Dim ColumnHeaders = From C In db.Customer _ Select _ C.Name //I would expect assignment to work like this but Name doesn't show Label.Text = ColumnHeaders.Name What's the correct way?
On Tue, 05 Aug 2008 14:14:34 -0700, gordigor <gordigor@community.nospam> wrote: > This is probably going to be an easy answer, but I can't find it > anywhere. I want to assign a labels .text property to a field returned > in a LINQ Query: > Dim db As New ClientDataContext > > Dim ColumnHeaders = From C In db.Customer _ > Select _ > C.Name > > //I would expect assignment to work like this but Name doesn't show > Label.Text = ColumnHeaders.Name Granted, I'm a relative LINQ newbie. But my understanding is that ColumnHeaders is a collection, not a single record. You could include a "Where" clause to limit the results to just one record, but I think even then you'd still have to extract that one record explicitly, rather than trying to access the "Name" property directly from the collection. This all assumes of course that "db.Customer" is itself a collection. If not, you may have other problems (or I might just not understand the VB syntax well enough :) ). Pete
gordigor wrote: > This is probably going to be an easy answer, but I can't find it > anywhere. I want to assign a labels .text property to a field returned > in a LINQ Query: > Dim db As New ClientDataContext > > Dim ColumnHeaders = From C In db.Customer _ > Select _ > C.Name > > //I would expect assignment to work like this but Name doesn't show > Label.Text = ColumnHeaders.Name > > What's the correct way? There doesn't seem to be any reason to use LINQ at all? Why not simply something like: Label.Text = db.Customer.First().Name -- Göran Andersson _____ http://www.guffa.com
"Göran Andersson" wrote in message news:%23HhsE019IHA.3344@TK2MSFTNGP02.phx.gbl... > gordigor wrote: >> This is probably going to be an easy answer, but I can't find it >> anywhere. I want to assign a labels .text property to a field returned in >> a LINQ Query: >> Dim db As New ClientDataContext >> >> Dim ColumnHeaders = From C In db.Customer _ >> Select _ >> C.Name >> >> //I would expect assignment to work like this but Name doesn't show >> Label.Text = ColumnHeaders.Name >> >> What's the correct way? > > There doesn't seem to be any reason to use LINQ at all? > > Why not simply something like: > > Label.Text = db.Customer.First().Name > > -- > Göran Andersson > _____ > http://www.guffa.com Ok. I was confused. Still I don't see the actual fields if I do Label.Text = db.Customer