Solved

For each loop to execute LINQ query failed without going through the loop?

Posted on 2008-06-22
1
501 Views
Last Modified: 2013-11-26
Build ok and no error message but when debug reached the 'for each... next' it skip over the loop...
I have Imported the following:
Imports System.Data
Imports System.Data.DataSet
Imports System.Data.OleDb
Imports Microsoft.Office.Interop.Access
Imports Microsoft.Office.Interop.Word
Imports System
Imports System.Collections
Imports System.Collections.Specialized
Imports System.Linq
Imports System.Linq.Expressions
Imports System.Data.Common
Imports System.Collections.Generic
Imports System.Text
Imports System.Data.SqlClient
 and used a typed dataset datatable as data source in the attached code snippet.
Can you tell what's wrong or missing?
Thank you.
Dim tiu As DataTable = ds.Tables(tblname)
        Dim dy As New dDataSet()
        Dim Th As DataTable = dy.Tables("th")
        Console.WriteLine("{0}", Me.ID.ToString)
        Console.WriteLine("{0}", ds.Tables(tblname).TableName.ToString)
 
        Dim thquery = From f In Th Where f.Field(Of String)("voc") = tiu.Rows(0).ToString Select New With {.v = f.Field(Of String)("voc"), .g = f.Field(Of String)("gP"), .s = f.Field(Of String)("subHead"), .ke = f.Field(Of String)("key")}
 For Each f In thquery
            Console.WriteLine("{0}", f.v)
            myrowTh = _vDtTh.NewRow()
            myrowTh(mycol) = f.v
            myrowTh(mycolgP) = f.g
            myrowTh(mycolsubHead) = f.s
            myrowTh(mycolkey) = f.ke
            _vDt.Rows.Add(myrowTh)
        Next

Open in new window

0
Comment
Question by:isischen
[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
1 Comment
 
LVL 16

Accepted Solution

by:
CuteBug earned 500 total points
ID: 21844393
This is because, the LINQ query returns no results due to which "thquery" is null.

Now since it is null, it will not enter the For Each loop.

Maybe the problem lies in your LINQ query. It might not be proper.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

707 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