Need help pronto!

  • Thread starter Thread starter Roshawn
  • Start date Start date
R

Roshawn

Hi all,

I've tried just about everything trying to get the following code to work:


Protected Sub Selecting(ByVal sender As Object, ByVal e As LinqDataSourceSelectEventArgs)
Dim db As myDataContext = New myDataContext(my_SQL2005Express_connection_here)
Dim brands = db.GetBrands() 'I get an error here
Dim alphabets() As Char = New Char() {"A", "B", "C", "D", "E", "F", "G"}
e.Result = From a In alphabets _
Group Join p In brands On a Equals p.name Into g = Group _
Order By a _
Select New With {.Key = a, .Count = g.Count(), _
.Brands = From f In g Order By f.name Select New With {.Text = f.name, _
.Link = f.name & ".aspx"}}
End Sub


I don't know what's happening, but using the DataContext object seems to yield no results.
Instead I get the this error: "The query results cannot be enumerated more than once."

What does this error mean? I've tried repeatedly to work around it, but it still persists.

Please help,
Roshawn
 
A last ditch effort proved successful! I got things working by doing the following:


Change this - Dim brands = db.GetBrands()
to this - Dim brands As List(Of Brand) = db.GetBrands().ToList

Change this - Group Join p In brands on a Equals p.name Into g = Group
to this - Group Join p In brands on a Equals p.name(0).ToString() Into g = Group


Note that Brand is a class in the DataContext class based on a table in the database. The
first change is what actually returns data from the database via the DataContext object.
The previous code returned nothing. In the second change, I supplied an item index of
zero(found that out by accident).

Good thing I wasn't ready to give up yet. Giving it one more go caused Lady Luck to look
my way. :)

Roshawn
 
Back
Top