0

有没有办法迭代objectResult?即就像在不指定列名的情况下迭代数据表的所有列和行一样。

我喜欢创建一个通用函数,它将显示对象结果的所有列。那么有可能实现这一目标吗?

Dim queryResults As Data.Objects.ObjectResult = CType(obj, Data.Objects.ObjectResult)

    If Not (queryResults Is Nothing) Then

        ' Create the representation. 
        Dim result As New Dictionary(Of String, Object)
        Dim enumerator As System.Collections.IEnumerator = Nothing
        enumerator = DirectCast(queryResults, System.Collections.IEnumerable).GetEnumerator()

        ' Iterate through the query results.  
        While enumerator.MoveNext() 
         ''How to get all columns ???
        End While
        ' Dispose the enumerator  
        DirectCast(enumerator, IDisposable).Dispose()





        Return result
    End If
    Return New Dictionary(Of String, Object)
4

1 回答 1

0

以这种方式尝试:

DataTable table = GetTable(); // Your Query to Get the data table.
foreach (DataRow row in table.Rows) // Loop over the rows.
{

    foreach (var item in row.ItemArray) // Loop over the items.
    {
       Console.WriteLine(item);
    }
}
于 2013-04-22T06:31:54.170 回答