In ADO.NET we have methods for starting a transaction, reading the query results, etc.
My question is, will such T-sql statements as BEGIN TRANSACTION
and particularly TRY-CATCH
work if I just include them to command-text and then ExecuteNonQuery
?
mySqlCommand.CommandText =
@"BEGIN TRY
SELECT TOP 1 [id] FROM myTable;
END TRY
BEGIN CATCH
SELECT ERROR_NUMBER() AS ErrorNumber;
END CATCH;"
var result = mySqlCommand.ExecuteScalar(); // or just mySqlCommand.ExecuteNonQuery()
PS: I know, I can just test this myself. But I am asking this as SO. So that afterwards someone like me will be able to just google that. So, obviously, I don't expect answers like 'why not just try'. Thank you.