Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

I am not sure how to write this For Each loop properly?

Posted on 2011-03-24
5
Medium Priority
?
236 Views
Last Modified: 2012-05-11
I am getting an error reading: Unable to cast object of type 'System.Data.DataTable' to type 'System.Data.DataRow'.

From my code:

   Dim rows As DataRow
        For Each rows In DtSet.Tables
            Me.myOutPutBuffer.AddRow()
            Me.myOutPutBuffer.HotelName = rows.Table.Columns(1).ToString()
        Next

I am not sure how to write this For Each loop properly?
0
Comment
Question by:Mr_Shaw
  • 2
  • 2
5 Comments
 
LVL 16

Assisted Solution

by:ToddBeaulieu
ToddBeaulieu earned 1048 total points
ID: 35209050
You're enumerating the tables, not the rows.

Dim row As DataRow
For Each row In DtSet.Tables(someTableIndex).Rows
    Me.myOutPutBuffer.AddRow()
    Me.myOutPutBuffer.HotelName = row.Columns(1).ToString()
Next

0
 
LVL 23

Accepted Solution

by:
wdosanjos earned 952 total points
ID: 35209091
I think it should be something like this:

Dim table As DataTable
Dim row As DataRow
For Each table In DtSet.Tables
	For Each row In table.Rows
		Me.myOutPutBuffer.AddRow()
		Me.myOutPutBuffer.HotelName = row(1).ToString()
	Next
Next

Open in new window

0
 
LVL 16

Assisted Solution

by:ToddBeaulieu
ToddBeaulieu earned 1048 total points
ID: 35209102
Depends on whether he wants all tables, or just the one.
0
 

Author Comment

by:Mr_Shaw
ID: 35210192
I am working with SQL Server 2005 SSISI.

 am connecting to a Excel Datasource.

I want to extract the rows from an excel spreadsheet (as long as they have data).
0
 

Author Closing Comment

by:Mr_Shaw
ID: 35230505
thanks
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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
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…
Integration Management Part 2
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

886 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