0

I am developing a project in C# with a SQL Server database.

I want to save some information in the database when a query has any conditions, so my idea was have a generic method that launches the commit of the transaction and, if the commit has the conditions required, saves the information.

My question: is there any way to obtain the SQL code of the transaction just before the .commit()?

For example, something like that:

public void insertInfo(object)
{
     using (Context context = new Context())
     {
         [Do an insert]
         [Do a second insert]
         [Do an update]     

         context.Save()
     }
} 

// In the Context
public void Save()
{
    [Here I want to get the SQL statement(s) that will be affected by the "transaction.Commit()"]
   transaction.Commit();
}
0

1 Answer 1

2

No there is no built-in command or function that gets the current code of the transaction.

You could build it yourself, by creating a string variable, and every time you execute a command in the function you add it to the variable, and then read the variable when you commit the transaction.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.