Solved

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

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

867 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

17 Experts available now in Live!

Get 1:1 Help Now