[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

dbrowne

8/5/2008 9:15:00 PM

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?

3 Answers

Peter Duniho

8/5/2008 9:51:00 PM

0

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

Göran Andersson

8/6/2008 12:40:00 AM

0

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...

dbrowne

8/6/2008 4:10:00 PM

0


"Göran Andersson" <guffa@guffa.com> 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...

Ok. I was confused. Still I don't see the actual fields if I do Label.Text =
db.Customer