Re: Typed Dataset and transactions in ADO.NET 2.0
- From: "John Sitka" <johnsitka@xxxxxxxxxxxxxxxxx>
- Date: Tue, 9 Jan 2007 08:07:14 -0500
Maybe this style...just across a couple of commands
try
{
SqlTransaction trans;
cmd_One.Connection = cmd_Two.Connection;
cmd_Two.Connection.Open();
trans = cmd_Two.Connection.BeginTransaction();
cmd_Two.Transaction = trans;
cmd_One.Transaction = trans;
try
{ int Execvar = 0;
object o = cmd_Two.ExecuteScalar();
Execvar = o == null ? 0 : Convert.ToInt32( o );
cmd_One.ExecuteNonQuery();
trans.Commit();
}
catch (SqlException sqlError)
{
trans.Rollback();
// Debug.WriteLine(sqlError.ToString());
bool bReturnLog = true;
bReturnLog = ErrorLog.ErrorRoutine(false,sqlError);
if (false == bReturnLog)
MessageBox.Show("Unable to write a log");
}
}
catch(Exception ex)
{
Debug.WriteLine(ex.ToString());
bool bReturnLog = true;
bReturnLog = ErrorLog.ErrorRoutine(false,ex);
if (false == bReturnLog)
MessageBox.Show("Unable to write a log");
}
finally
{
if (cmd_One.Connection.State.ToString() == "Open")
{
cmd_One.Connection.Close();
}
if (cmd_Two.Connection.State.ToString() == "Open")
{
cmd_Two.Connection.Close();
}
}
"RobinS" <RobinS@xxxxxxxxxxxxxxx> wrote in message news:ROmdnTvlotJwCT_YnZ2dnUVZ_revnZ2d@xxxxxxxxxxxxxx
You can't use transactions with a table adapter. If you want to do that,
you'll need to use a data adapter.
Dim dt as New DataTable()
Dim cn as New SqlConnection(ss)
Dim da As New SqlDataAdapter(ss, cn)
da.SelectCommand.Parameters.AddWithValue("@OrderID", 1050")
'define updating logic for sqldataadapter here (set up InsertCommand, DeleteCommand, UpdateCommand)
cn.Open()
da.Fill(tbl)
'modify the contents
Using txn as SqlTransaction = cn.BeginTransaction()
'set the transaction property of the da's commands
da.UpdateCommand.Transaction = txn
da.SelectCommand.Transaction = txn
da.DeleteCommand.Transaction = txn
'submit the changes
da.Update(dt)
'commit the changes
txn.Commit()
End Using
cn.Close()
Robin S.
---------------------------------
"STeW" <STeW@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:0EBBF267-80CC-4343-AA02-458B7F148FF8@xxxxxxxxxxxxxxxx
Hi all,
I have a general question about typed datased and transaction. Do you
anybody know the best way how to manage transaction typed dataset? Generaly,
when I create dataset and INSERT/UPDATE/DELETE command in a table adapter,
there are connections on commands which are not in transaction.
I need to have it in transaction. I can do it programaticly. I'm asking if
anybody knows about any property which enables code generation for
transaction support in typed dataset.
Thanks
Stepan
.
- Follow-Ups:
- Re: Typed Dataset and transactions in ADO.NET 2.0
- From: RobinS
- Re: Typed Dataset and transactions in ADO.NET 2.0
- References:
- Re: Typed Dataset and transactions in ADO.NET 2.0
- From: RobinS
- Re: Typed Dataset and transactions in ADO.NET 2.0
- Prev by Date: Re: What are OleDbParameter names with 'Original_' prefix?
- Next by Date: Re: Correct way of using OleDbAdapter and DataSet to update Access database?
- Previous by thread: Re: Typed Dataset and transactions in ADO.NET 2.0
- Next by thread: Re: Typed Dataset and transactions in ADO.NET 2.0
- Index(es):
Relevant Pages
|