?
Solved

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

Posted on 2008-06-22
1
Medium Priority
?
502 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 2000 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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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.…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

765 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