Q:

Error declaration or range of a variable

I am a beginner in vb.net, recently, I have written this query : 
I don't think that explain you the goal of my procedure is important (if it is, do not hesitate to tell me.) 
I have two queries: req1 and req2 
For i = 0 To My_List.Count - 2

    For j = i + 1 To My_List.Count - 1

        Dim req1 = From Row1 In list_Rows Where Row1.C1.Equals(My_List(i)) Select Row1
        Dim A As Integer = 0

        For Each r In req1

            Dim req2 = From Row2 In list_Rows Where (Row2.C1.Equals(My_List(j)) AndAlso Row2.C2.Equals(Row1.C2)) Select Row2
            A += req2.count

        Next r

    'process....

    Next

Next

As you can see in the code below, at the end of req1 I get "Row1". 
I'd like to use Row1 in the second req2 queries. 
But I have the following error message: 
"The name 'Row1' is not declared or is not in the current range."
How can I solve this problem?
Thank you in advance for your help!

A:

Your question is tricky to understand, but I suspect you just need to use r (the row in the current iteration) instead of Row1. The name Row1 only has any meaning within the query expression itself. So try this:
Dim req2 = From Row2 In list_Rows Where (Row2.C1.Equals(My_List(j)) AndAlso 
                                         Row2.C2.Equals(r.C2)) Select Row2

(I'm pretty sure there will be more efficient ways of achieving this, admittedly... you should look into joins. However, this will at least get you moving forward a bit.)

