LINQ Query based on user preferences
- by Chris Phelps
How can I do this better (so it actually works : )
I have a LINQ Query that includes an order by that is based on a user preference. The user can decide if they would like the results ordered asc or desc.
If fuserclass.SortOrder = "Ascending" Then
Dim mydat = (From c In dc.ITRS Order By c.Date Ascending Select c)
Else
Dim mydat = (From c In dc.ITRS Order By c.Date Descending Select c)
End If
For each mydata in mydat ***<<<error "mydat is not declared"***
I know I could put my For Each loop inside the If and Else, but that seems silly to have the same code twice. I know you know of a better way : )