Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Loop or iterate through resultset or recordset by column, using C# only Expand / Collapse
Author
Message
Posted Monday, October 21, 2013 5:32 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, May 15, 2014 8:51 PM
Points: 183, Visits: 480
I have a result set like (in SSIS actually) -

ID, Name, Address
1,John, Japan
2,Sarah, UK
3,Jeremy, USA

I want to be able to select any column out of the above in the result set/record set and then iterate over that column's rows. How do I do that ?
Post #1506927
Posted Tuesday, October 22, 2013 2:19 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 8:55 AM
Points: 13,570, Visits: 11,383
string columnname = "Name";
DataTable myTable; -- don't forget to initialize datatable

foreach(Datarow row in myTable.Rows){
Console.WriteLine(row[columnname]);
}

Haven't tested it, but it shouldn't be far off.




How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1507011
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse