Loop or iterate through resultset or recordset by column, using C# only

  • 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 ?

  • 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.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply