2013-04-22 39 views
0

有没有办法迭代objectResult? 也就是说就像遍历所有列和行的数据表而不指定列名。如何迭代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) 
+1

您可以更新您试图代码问题至今 – Damith 2013-04-22 06:56:25

+1

没有什么比你告诉我,点心枚举作为System.Collections.IEnumerator =仅此而已 enumerator = DirectCast(queryResults,System.Collections.IEnumerable).GetEnumerator() '遍历查询结果。 While enumerator.MoveNext() End While – tsohtan 2013-04-22 06:57:54

回答

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); 
    } 
}