Click here to Skip to main content
15,898,222 members
Home / Discussions / C#
   

C#

 
GeneralRe: Where are app settings stored? Pin
Anders Molin20-Jan-09 0:10
professionalAnders Molin20-Jan-09 0:10 
AnswerRe: Where are app settings stored? Pin
#realJSOP20-Jan-09 2:29
professional#realJSOP20-Jan-09 2:29 
QuestionConnection and transaction Pin
mpavas19-Jan-09 23:25
mpavas19-Jan-09 23:25 
AnswerRe: Connection and transaction Pin
musefan19-Jan-09 23:36
musefan19-Jan-09 23:36 
GeneralRe: Connection and transaction Pin
mpavas19-Jan-09 23:48
mpavas19-Jan-09 23:48 
GeneralRe: Connection and transaction Pin
musefan20-Jan-09 0:26
musefan20-Jan-09 0:26 
GeneralRe: Connection and transaction Pin
mpavas20-Jan-09 1:30
mpavas20-Jan-09 1:30 
GeneralRe: Connection and transaction Pin
Ben Fair20-Jan-09 10:32
Ben Fair20-Jan-09 10:32 
All you need is the Connection and Transaction objects. You create the Transaction from the Connection, something like:

DbTransaction tran = conn.BeginTransaction();


Then, you can do everything off of these objects (create the commands from the connection, etc.); be sure to set the command's Transaction property approriately; so you'd have something like:

DbConnection conn = GetConnection();
DbTransaction tran = conn.BeginTransaction();
bool success = true;
...
success = MethodA(conn, tran);
success = success && MethodB(conn, tran);
success = success && MethodC(conn, tran);
if(!success)
    tran.Rollback();
else
    tran.Commit();
...

private bool MethodA(DbConnection conn, DbTransaction tran)
{
    bool result = true;
    DbCommand comm = conn.CreateCommand();
    comm.CommandText = ...
    comm.Transaction = tran;
    ...
    return result;
}
...
private bool MethodB(DbConnection conn, DbTransaction tran)
...
private bool MethodC(DbConnection conn, DbTransaction tran)
...


If you want to make the Connection and Transaction objects class-level variables and have the methods access them that way instead of passing them in, is up to you; I just prefer this way.

Keep It Simple Stupid! (KISS)

GeneralRe: Connection and transaction Pin
mpavas20-Jan-09 18:56
mpavas20-Jan-09 18:56 
QuestionHow to convert a pdf into doc/word Pin
inzibharti19-Jan-09 23:23
inzibharti19-Jan-09 23:23 
QuestionCount number of rows in listview Pin
Deques19-Jan-09 23:19
Deques19-Jan-09 23:19 
AnswerRe: Count number of rows in listview Pin
musefan19-Jan-09 23:34
musefan19-Jan-09 23:34 
GeneralRe: Count number of rows in listview Pin
Deques19-Jan-09 23:36
Deques19-Jan-09 23:36 
Questionprinting invoice Pin
s4_sabahatf19-Jan-09 23:08
s4_sabahatf19-Jan-09 23:08 
AnswerRe: printing invoice Pin
SeMartens20-Jan-09 0:05
SeMartens20-Jan-09 0:05 
GeneralRe: printing invoice Pin
SeMartens20-Jan-09 2:01
SeMartens20-Jan-09 2:01 
Questioncaspol.exe Pin
subramanyeswari19-Jan-09 20:54
subramanyeswari19-Jan-09 20:54 
AnswerRe: caspol.exe Pin
Sathesh Sakthivel19-Jan-09 21:05
Sathesh Sakthivel19-Jan-09 21:05 
GeneralRe: caspol.exe Pin
subramanyeswari20-Jan-09 0:25
subramanyeswari20-Jan-09 0:25 
QuestionSigned DLL in Windows Service Pin
satsumatable19-Jan-09 20:40
satsumatable19-Jan-09 20:40 
AnswerRe: Signed DLL in Windows Service Pin
Sathesh Sakthivel19-Jan-09 20:48
Sathesh Sakthivel19-Jan-09 20:48 
QuestionDeep copy of array list, where array list as member of collection Pin
ptr_Electron19-Jan-09 19:57
ptr_Electron19-Jan-09 19:57 
AnswerRe: Deep copy of array list, where array list as member of collection Pin
SeMartens19-Jan-09 21:43
SeMartens19-Jan-09 21:43 
AnswerRe: Deep copy of array list, where array list as member of collection Pin
User 665819-Jan-09 22:15
User 665819-Jan-09 22:15 
QuestionClickOnce Deployment... Pin
Illegal Operation19-Jan-09 16:32
Illegal Operation19-Jan-09 16:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.