Reputation: 121
I am using Microsoft.Practices.EnterpriseLibrary.Data
for database related activities in my application. I have written some code where I am executing a deletion as well as updating some records using two ExecuteNonQuery
. I want to put these in a single transaction. How I can implement that using Microsoft.Practices.EnterpriseLibrary.Data
?
What modification is required in the following code to use a transaction?
Code is as following:
int iUpdate = 0;
Database db = DatabaseFactory.CreateDatabase(dbRegion);
try
{
string sSQL = "DELETE FROM table1 WHERE Number = 1 ";
db.ExecuteNonQuery(CommandType.Text, sSQL);
string sqlCommand = "spInsertToTable";
DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);
iUpdate = db.ExecuteNonQuery(dbCommand);
}
catch (Exception ex)
{
throw;
}
Upvotes: 2
Views: 1820