Tags » Developing

How to use transactions in .NET

This is a very high level example of using transactions with ADO.NET objects in C#. Please refer the inline comments for instructions.

private void TransactionExample ()

{
 SqlTransaction transaction = null;
 SqlConnection con = null;
 
 // they will be used to decide whether to commit or rollback the transaction
 bool query1 = false;
 bool query2 = false;

try
 {
 con = new SqlConnection(CONNECTION_STRING);
 con.Open();

// begin the transaction
 transaction = con.BeginTransaction();

// Run some queries in DB
 using (SqlCommand cmd = con.CreateCommand())
 {
 cmd.CommandType = CommandType.Text;
 cmd.CommandText = "your query"

// assosiate this command with transaction
 cmd.Transaction = transaction;

query1 = cmd.ExecuteNonQuery() == 1;
 }

// Uncomment the line below to test if transaction works
 // throw new Exception("Transaction test!");

// Run more queries
 using (SqlCommand cmd = con.CreateCommand())
 {
 cmd.CommandType = CommandType.Text;
 cmd.CommandText = "your query";

// assosiate this command with transaction
 cmd.Transaction = transaction;

query2 = cmd.ExecuteNonQuery() == 1;
 }

if (query1 && query2)
 {
 // Commit transaction because both queries run successfully
 transaction.Commit();
 }
 }
 catch
 {
 // Don't run queries in DB because there is an error
 transaction.Rollback(); 
 }
 finally
 {
 con.Close();
 }
} 8 more words
Developing

Creating S.M.A.R.T. Goals. How to do it? - YouTube


Developing sound goals is critical to your success. A S.M.A.R.T. goal is a simple tool used by many to clearly set and articulated sound goals to attain spec…
http://bit.ly/1Ce5CvB

Career Inspiration

Interested in switching up your career?
Or maybe learning some new technology skills?

This Website: http://skillcrush.com/ has the best articles I’ve come across for inspiring a career in web developing and design. 84 more words

Property Investing - How To Make 25% Every Time


Property Developing is a complex business but this report will point you in the right direction, give you a timeline and a course of action so you know what to expect.
http://bit.ly/1y1ziWi

Property Investing - How To Make 25% Every Time


Property Developing is a complex business but this report will point you in the right direction, give you a timeline and a course of action so you know what to expect.
http://bit.ly/1y1ziWi

Class, Tues, 1/27/2015

Session One

Developing and Revising Essay Two

  • Use your second draft to develop your best idea. Find other images or videos that allow you to discuss that idea.
  • 183 more words
Class