Solved

How to return all records in a LINQ query?

Posted on 2014-12-04
3
70 Views
Last Modified: 2016-02-16
I am using the following code (which works) to return all records, but I can't get it to work without selecting each field individually. I would like to know the syntax to retrieve all fields, because some tables will have a lot of them.

        Try
            Dim db As New DataContext("C:\Grow.mdf")
            Dim Strains As Table(Of Strain) = db.GetTable(Of Strain)()
            Dim q = From objStrain In Strains Select objStrain.StrainID, objStrain.Code, objStrain.Name Order By Code

            If q.Count = 0 Then
                MsgBox("Nothing returned.")
                Exit Sub
            End If

            DataGridView1.DataSource = q

        Catch ex As Exception
                MsgBox(ex.Message)
        End Try

Open in new window

0
Comment
Question by:Sheryl Landis
  • 2
3 Comments
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
Comment Utility
Hi  Sheryl Landis;

Just use the local variable objStrain by itself as shown below

Dim q = From objStrain In Strains Order By objStrain.Code Select objStrain

Open in new window

0
 

Author Closing Comment

by:Sheryl Landis
Comment Utility
Thank you!!!!
0
 
LVL 62

Expert Comment

by:Fernando Soto
Comment Utility
Not a problem Sheryl; glad I was able to help.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now