2011-02-14 114 views
1

我有一个SQLite数据库,我希望从每条记录读取记录并执行一段代码。尝试在while循环内捕获

我使用了尝试catch里面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块与前任是被捕获,while循环的下一次迭代失败,因为它似乎是一个ex被捕获的时刻,与SQLite数据库的连接被关闭,尽管连接属性表明它已打开。

任何想法???

+0

什么是实际异常? – 2011-02-14 10:12:27

回答

0

您可以将尝试捕捉内的所有代码到返回boolean值的功能,并采取了ByRef参数作为函数

该函数的返回值担任了成功的指标或失败的操作,即异常的结果被提出与否。