• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 129
  • Last Modified:

How to return all records in a LINQ query?

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
Sheryl Landis
Asked:
Sheryl Landis
  • 2
1 Solution
 
Fernando SotoCommented:
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
 
Sheryl LandisAuthor Commented:
Thank you!!!!
0
 
Fernando SotoCommented:
Not a problem Sheryl; glad I was able to help.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now