VB.NET 3.5 Problem With LINQ to SQL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • KodeKrazy
    New Member
    • Mar 2008
    • 32

    VB.NET 3.5 Problem With LINQ to SQL

    Can any one explain to me why I am getting the error "UGroup is not declared." on the attached bit of code? I have hundreds of similarly formatted methods that work perfectly! Thanks in advance!

    KK

    Code:
            
            Dim linqUsers As New linqUserDataDataContext
            Dim UGroups = From UG In linqUsers.Users Select UG.UserGroupID, UG.Description
    
            For Each UGroup In UGroups
    
                   'Populate a data grid view...
    
            Next 'UGroup
    Last edited by KodeKrazy; Aug 13 '08, 02:54 PM. Reason: Clarification
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Originally posted by KodeKrazy
    Can any one explain to me why I am getting the error "UGroup is not declared." on the attached bit of code? I have hundreds of similarly formatted methods that work perfectly! Thanks in advance!

    KK

    Code:
            
            Dim linqUsers As New linqUserDataDataContext
            Dim UGroups = From UG In linqUsers.Users Select UG.UserGroupID, UG.Description
    
            For Each UGroup In UGroups
    
                   'Populate a data grid view...
    
            Next 'UGroup

    I don't think that your declaration is correct...
    Looking at examples I'm noting that you should be declaring UGroups like:
    Code:
            
            Dim linqUsers As New linqUserDataDataContext
            Dim UGroups = From UG In linqUsers.Users Select new {UG.UserGroupID, UG.Description}
    -Frinny

    Comment

    • KodeKrazy
      New Member
      • Mar 2008
      • 32

      #3
      It's very peculiar. I thought maybe I had the SQL Data Class built wrong but I can place EXACTLY the same LINQ statement 5 lines down, inside another For Next loop and it does not give me the error. I have tried renaming it (on both instances) everything from a single letter to dbMonkeys, it works no matter what in the other loop, but not the first one.

      I even tried closing VS2008 and reopening the project. Not sure what to try next...

      KK

      Comment

      Working...