有没有办法在Visual Basic中实际运行查询之前检查查询是否可执行

时间:2014-12-17 07:44:44

标签: database vb.net transactions

我有这个代码。这段代码没有任何问题,因为它可以无误地执行并获得我想要的结果。但是,在实际调用" cmd.ExecuteNonQuery"之前,我是否有办法检查查询是否可执行而没有错误。和" transaction.commit()"。

    '....Database connection code....
    '....transacation start.....

    try
       '....Query string population.....
       'what I want to do... A check of query whether ExecuteNonQuery will success
       cmd.ExecuteNonQuery()

       'Anything goes wrong with ExecuteNonQuery, it will catch exception
       'transaction end and dispose database connection

    catch ex As exception
        'transaction rollback, end and dispose database connection
        Console.WriteLine("ERROR DETECTED : " & ex.Message)
    end try

0 个答案:

没有答案