【发布时间】:2013-11-05 17:39:32
【问题描述】:
我在 DataTable 中存储了一个 ADO 记录集。我已经迭代到它的结尾。在相同的代码中,我想重申它,但它给了我一个错误 -
Error: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IndexOutOfRangeException: There is no row at position -1.
at System.Data.RBTree`1.GetNodeByIndex(Int32 userIndex)
at System.Data.RBTree`1.get_Item(Int32 index)
at System.Data.DataRowCollection.get_Item(Int32 index)
我看过这里 - http://www.techrepublic.com/blog/10-things/10-plus-mistakes-to-avoid-when-using-vba-recordset-objects/ 但它并没有给我一个将“行指针”移回第一行的确切方法。
我该怎么做?
【问题讨论】:
-
看起来你正在绑定
.get_Item(-1) -
发布您的代码!我们不介意读者!
-
不要使用 ADO。相反,请使用
DbConnection和朋友,或者更好的是,使用实体框架。 -
老式 ADO 曾经有一个 MoveFirst 方法。你能智能感知类似的东西吗?
-
@SLaks - 实际上,代码和完整的故事在这里 - stackoverflow.com/questions/19780858/looping-a-datatable-twice
标签: c#