Solved

How to return all records in a LINQ query?

Posted on 2014-12-04
3
76 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 40481635
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
ID: 40481669
Thank you!!!!
0
 
LVL 63

Expert Comment

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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

726 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