Solved

How to return all records in a LINQ query?

Posted on 2014-12-04
3
74 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
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 62

Expert Comment

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

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to use laptop or pad camera in vb.net windows application 2 70
VB.NET 1 21
No Data for DropDown List 2 22
vb.net 1 month apart 11 24
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 …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

813 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

10 Experts available now in Live!

Get 1:1 Help Now