1

我有一个 SQLite 数据库,我希望从中读取记录并针对每条记录执行一段代码。

我正在使用带有 Try Catch INSIDE 的 While 循环...

代码如下:-

            result = slcom.ExecuteReader()
            'TODO: There is a problem with this while loop whereby if an ex is caught the connection
            '      to the database is closed.
            While result.Read
                Try

                       < do some stuff here >

                Catch ex As Exception
                    incrementFailoverCount(result("fid"))
                End Try
            End While
            result.Close()

问题是,一旦进入 Try 块并捕获了一个 ex,while 循环的下一次迭代就会失败,因为似乎在捕获 ex 的那一刻,与 SQLite 数据库的连接就关闭了,尽管连接属性表明它开了。

有任何想法吗 ???

4

1 回答 1

0

您可以将 Try Catch 中的所有代码移动到一个函数中,该函数返回一个布尔值并将 ByRef 参数作为函数的结果

该函数返回值用作操作成功或失败的指示符,即是否引发异常。

于 2011-03-27T09:32:21.147 回答