从数据表输出单个列

时间:2010-09-24 22:05:31

标签: vb.net datatable

所以这似乎不应该那么困难,但显然我忽略了什么......?我有一个有4列的数据表。我想从数据表输出第二列。这是我到目前为止所得到的:

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

2 个答案:

答案 0 :(得分:1)

您应该将输出列值的行更改为:

Response.Write(row(1))

答案 1 :(得分:0)

或者这个:

Dim col As DataColumn = dt.Columns(1)

回复于(行(列))

看起来您的问题是col变量未设置为任何