Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to return all records in a LINQ query?

Posted on 2014-12-04
3
Medium Priority
?
109 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 64

Accepted Solution

by:
Fernando Soto earned 2000 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 64

Expert Comment

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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

618 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