I have this code. There is nothing wrong with this code as it can execute without error and get the result I want. However, I am wandering whether there is a way to check a query is executable without error before actually calling the "cmd.ExecuteNonQuery" and "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