创建一个数据表,然后填充它,创建表如下:
Private Function CreateDataSource() As DataTable
    'creates the columns for the datatable 
    Dim dt As New DataTable 'create new datatable
    'add appropriate columns to the table
    Dim colImage As New DataColumn("Field1", GetType(Boolean))
    colImage.DefaultValue = bShowExtraInfo
    dt.Columns.Add(colImage)
    dt.Columns.Add("Field2", GetType(String))
    Return dt 'return the table
End Function
然后在您的代码中使用它,如下所示:
Dim dt As DataTable = CreateDataSource() 'create the data table
    Dim dr As DataRow
        For Each x In y 'cycle through x and add to table
                dr("Field1") = tableAvalue
                dr("Field2") = tableBvalue
                dt.Rows.Add(dr)
            End If
        Next
    gvEverything.DataSource = dt
    gvEverything.DataBind()