Click here to Skip to main content
15,885,914 members

Comments by Ekjon (Top 17 by date)

Ekjon 10-Aug-17 15:20pm View    
Hi Peter, Sorry I pasted an older version of the code. I did in fact change it to have a new object every time like you suggested. e.g.
for (var i = 0; i < statcount; i++) {      
         var statCopy = stat;      
         statCopy.statId = document.getElementById("statId-" + (i + 1) + "").value;      
         ......      
         statList.push(statCopy);
}


But it did not make a difference. Debugging shows the loop correctly assigns values to the array of objects. However, when I try to do the post in another click method, now the array contains all the same values for each slot.
Ekjon 18-Mar-11 18:32pm View    
I found an example like this:
TransactionOptions options = new TransactionOptions();
options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
options.Timeout = new TimeSpan(0, 2, 0);
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options))
{
using (SqlConnection connA = new SqlConnection(connStringA))
{
using (SqlCommand cmdA = new SqlCommand(sqlStmtA, connA))
{
int rowsAffectedA = cmdA.ExecuteNonQuery();
if (rowsAffectedA > 0)
{
using (SqlConnection connB = new SqlConnection(connStringB))
{
using (SqlCommand cmdB = new SqlCommand(sqlStmtB, connB))
{
int rowsAffectedB = cmdB.ExecuteNonQuery();
if (rowsAffectedB > 0)
{
transactionScope.Complete();
}
} // Dispose the second command object.
} // Dispose (close) the second connection.
}
} // Dispose the first command object.
} // Dispose (close) the first connection.
} // Dispose TransactionScope object, to commit or rollback transaction.

My question is: do I have to use the If(rowsAffectedA > 0) to go for the next transaction, or I can directly go for transactions 1,2,3,4 and If one fails, at the end - the scope object will automatically roll back all? If it does, should I call the Complete() method anyway?

Thanks.
Ekjon 18-Mar-11 17:29pm View    
Thanks Henry.
Ekjon 18-Mar-11 17:29pm View    
Thanks Mika.
Ekjon 17-Jan-11 14:24pm View    
I tried all these before. But I had some other complexities - like the whole page is built dynamically based on some data - so I had to force a reload and use a querystring. Otherwise wasn't working no matter what I did. Thanks to all of you for your time and help.