VB.NET Linq To SQL Data not showing in DataGrid (Winforms)

Working on a simple form.  At least I thought.  Need to capture payments for an accounting system and I'm trying to use link for the first time.  Following "Linq in Action" to help me.  

1.  I added my Linq to SQL class (easy enough)
2.  Added the table I needed to the dbml (easy enough)

I go to write code from the examples I see and my grid is totally empty.

'Get Data from database
Dim db As New PurchaseOrderDataContext
Dim query = From aPO In db.PurchaseOrders
                      Select aPO
'Set results to Grid
Me.dgPayments.DataSource = query

Open in new window

I haven't gotten to the ability to add debits and credits via LINQ yet.  Any idea why I'm not seeing any data?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:
Hi CipherIS;

The first thing to remember is that Linq queries like the one in your question does not execute immediately therefore your variable query only holes a quiry to be executed on the SQL Server and does not yet hold the results of that query. To get the query to execute you need to iterate over the collection or use one of the methods which will cause it to iterate through the collection such as ToList. Try your query like the following and you should see some results.

Get Data from database
Dim db As New PurchaseOrderDataContext

Dim query = (From aPO In db.PurchaseOrders
             Select aPO).ToList()

'Set results to Grid
Me.dgPayments.DataSource = query

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CipherISAuthor Commented:
AWESOME!   Thank you.
Fernando SotoRetiredCommented:
Not a problem CipherIS, glad to help.

There is a free tool that you can download written by the person who wrote C# in a Nutshell. They also have a paid version but seeming you are programming in VB it will not be worth it to purchase it because the only thing that comes with it is intelliSense but it is only available for C# but not for the VB language. It also has lots of examples and it is possible to download more, this is available for both languages without the paid version.

CipherISAuthor Commented:
I actually do program in C#.  This just happens to be a VB.NET app.  I write in both languages among others.  Basically, I write whatever I'm paid to write in.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.