2

I'm creating a mock instance of one of my datarows for testing.

The row I'm trying to duplicate from our database contains 37 columns with different variables.

Is there any chance when debugging to get the information out in clean text for simple editing of my mock objects?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Andreas
  • 1,421
  • 3
  • 16
  • 32
  • 1
    http://stackoverflow.com/questions/12823371/datacolumn-name-from-datarow-not-datatable Best Answer – Ajit Sep 28 '16 at 09:35

3 Answers3

9

I had to adjust Nikhil's Cast:

var colNames = dr.Table.Columns.Cast<DataColumn>().Select(x => x.ColumnName).ToList();
7

How about

var colNames = dr.Table.Columns.Cast(Of DataColumn)
                               .Select(x => x.ColumnName).ToList()
Nikhil Agrawal
  • 47,018
  • 22
  • 121
  • 208
1

Solved it like this since I couldnt get Nikhils code to work.

        int i = 0;
        while(i<looprow.Table.Columns.Count)
        {
            Debug.WriteLine(looprow.Table.Columns[i].ColumnName);
            i++;
        }
Andreas
  • 1,421
  • 3
  • 16
  • 32