你怎么知道“DataTable.Load()”是否已完成加载?

时间:2011-09-16 05:47:59

标签: .net datatable datareader

当您使用DataTable时,您如何知道所有结果数据是否都加载到DataTable.Load?或者更确切地说,我们如何知道DataReader是否已完成加载数据?

代码:

'Connection, command etc.
Dim Reader as SqlDataReader = Command.ExecuteReader()
Dim SomeDataTable as new DataTable()
SomeDataTable.load(Reader); 'When will loading be finished or how would you know?

我正在使用VB.NET

更新

这是我的原始代码:

Private Function LoadPRS(ByVal Username As String) As DataTable
    Dim PRSList As New DataTable

    Using Connection As New SqlConnection(ConfigurationManager.ConnectionStrings("DBCS").ToString)
        Using Command As New SqlCommand _
            ("select * from products", Connection)

            Connection.Open()
            Using Reader = Command.ExecuteReader
                PRSList.Load(Reader)
            End Using
        End Using
    End Using

    Return PRSList
End Function

1 个答案:

答案 0 :(得分:3)

据我所知,该方法是同步的。你知道它已经完成了,因为该方法会返回给你。如果它没有“完成”,它就会抛出异常。