Solved

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

Posted on 2008-06-22
1
496 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
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

760 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

19 Experts available now in Live!

Get 1:1 Help Now