Dot Net Capsules

A Capsule on .NET, everyday, keeps you .NetHealthy!!!!

My Photo
Name:

Co-founder at mymoneysage.in Result oriented Tech Leader Programmer, Sotware Architect, Techologist Polyglot software developer, expert in multiple tech stack Specialties: Machine learning, Artificial intelligence, Conversational Interface, RASA, AWS, Lex, REST, GraphQL, PWA, C#, .NET, ASP.NET, XML, Web services, Agile, SCRUM

Tuesday, April 26, 2005

Using Trasaction with DataAdapters

Following are the steps to use SqlTransaction with SqlDataAdapter
1. Create a Connection :
SqlConnection con = new SqlConnection(connectionString);
Con.Open();


2. Create a Transaction :
SqlTransaction tran = con.BeginTrasaction();

3. Create a Command object :
SqlCommand command = new SqlCommand(query);

4. Create a DataAdapter :
SqlDataAdapter dataAdapter = new SqlDataAdapter(con);
dataAdapter.SelectCommand = command;
//Fill a dataset
//modify dataset
//Create Update, Insert, Delete command using SqlCommandBuilder and SqlDataAdapter
//update the data into Dataset to Database using update method
dataAdapter.Update(dataset);

5. Commit or Rollback the Trasaction :
Tran.Commit();
Or
Tran.Rollback();

When you create a DataAdapter using the Connection object, Trasaction associated with the connection object is also associated with the DataAdapter object.

0 Comments:

Post a Comment

<< Home

You Visitor Number:
Free Web Site Counter
Free Counter
free counters