我有这个代码。这段代码没有任何问题,因为它可以无误地执行并获得我想要的结果。但是,在实际调用" 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