Solved

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

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

Industry Leaders: 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

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

733 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