views:

16

answers:

2

So this doesn't seem like it should be that difficult, but apparently I'm overlooking something..? I have a datatable that has 4 columns. I want to output only the second column from the datatable. Here's what I've got so far:

Dim dt As New DataTable
** Datatable is set here **
Dim row As DataRow
Dim col As DataColumn

For Each row In dt.Rows
    'Output Column 2 here
    'This is what I had which obviously doesn't work
    Response.Write(row(col(1)))
    Response.Write("<br />")
Next
+1  A: 

You should change the line where you output the column value to this:

Response.Write(row(1))
Fredrik Mörk
A: 

Or this:

Dim col As DataColumn = dt.Columns(1)

Response.Write(row(col))

Looks like your issue is that the col variable wasn't set to anything

MikeG