Link to home
Start Free TrialLog in
Avatar of Tony Gardner
Tony GardnerFlag for United States of America

asked on

Getting Error [FieldName] is not a member of 'System.Array' in LINQ Query

Hello Experts.

I've successfully built quite a few LINQ queries in my Windows Form project thus far, but for some reason, I am not able to get the "For Each" code to recognize the fields I'm selecting. The error condition is "[FieldName] is not a member of 'System.Array' in LINQ Query".

I did my homework and found that I needed to add Imports System.Linq in my declarations, and sure enough it was missing (which I find strange since this has been working fine for all my other LINQ queries).

My primary objective with the code is a grab a Picture from a related table, and populate a PictureBox control with the result. Here's the code I've got right now:
Private Sub MyPlayerPicture()
    ' Process Picture separately to better handle Null values
    Dim APAID As Integer = CInt(Me.MyPlayersAPAID.Text)
    Dim GetPicture =
         (
             From RosterData In SNAPDataSet.RosterView
             Where Not RosterData.IsNull("Player_Picture")
             Select RosterData.Player_Picture
         ).ToList
    If GetPicture.Count = 0 Then
        Me.MyPlayersPicture.Image = My.Resources.Silhouette
    Else
        For Each row In GetPicture
            If row.APA_Player_ID = APAID Then
                Dim ppBlob() As Byte = row.Player_Picture
                Dim ppStream As New MemoryStream(ppBlob)
                Me.MyPlayersPicture.Image = Image.FromStream(ppStream)
                Exit Sub
            End If
        Next row
    End If
End Sub

Open in new window


The lines with error conditions are the ones which reference row.[FieldName]. I can also confirm that Intellisense doesn't recognize row as associated with the .

I have tried several other permutations of the above before posting this including removing the Where clause, as well as fetching single records by setting the Where clause to "Where Not RosterData.IsNull("Player_Picture") AndAlso RosterData.APA_Player_ID = APAID".

BTW, this subroutine is called by its predecessor which populates other fields on the same form when the record is changed as shown here:
Private Sub MyPlayersBindingSource_CurrentChanged(sender As Object, e As EventArgs) Handles MyPlayersBindingSource.CurrentChanged
    Dim APAID As Integer = CInt(Me.MyPlayersAPAID.Text)
    Dim LoadData =
         (
             From RosterData In SNAPDataSet.Roster
             Where RosterData.APA_Player_ID = APAID
             Select RosterData.APA_Player_ID, RosterData.Player_Name, RosterData.SL
         ).ToList
    For Each row In LoadData
        If row.APA_Player_ID = APAID Then
            Me.MyPlayersName.Text = row.Player_Name
            Me.MyPlayersSL.Value = row.SL
        End If
    Next row
    Call MyPlayerPicture()
End Sub

Open in new window


Please note that there are no error conditions with the above subroutine. All three fields are being set when the program is run.

Thanks In Advance!
ASKER CERTIFIED SOLUTION
Avatar of Tony Gardner
Tony Gardner
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tony Gardner

ASKER

Who knows? Maybe someone else will benefit from this!