Transactions and Typed DataSets, Adapters (Visual Studio 2005)

M

Mike Smith

I've seen several posts related to using transactions and typed
datasets/adapters. Visual Studio 2005 has an excellent code generator
for data adapters but at first glance it appears that there is no way
to access the necessary properties for transaction management.

If you take a look at the generated code you'll notice that the class
declaration for the data adapters contains the "partial" modifier. This
is very important because it allows you to create a supplementary
partial class which will be merged with the generated class. Here's the
example partial class I created to go with my generated adapter:

using System;
using System.Data.SqlClient;
using System.ComponentModel;
using System.Collections.Generic;
using System.Text;

namespace Sulzer.HelpDesk.Data.TicketDataSetTableAdapters
{
/// <summary>
/// Partial adapter class
/// </summary>
public partial class TicketTableAdapter : Component
{
public void SetTransaction(SqlTransaction pTransaction)
{
Adapter.UpdateCommand.Transaction = pTransaction;
Adapter.InsertCommand.Transaction = pTransaction;
Adapter.DeleteCommand.Transaction = pTransaction;
Adapter.SelectCommand.Transaction = pTransaction;
}
}
}

The only trick to using your own partial class is to use the exact same
namespace and classname for your partial class. You now have the
ability to create public properties to access any generated private
member. Lastly, don't get too crazy with this. Expose what you need to
get the job done.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top