Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Hi.

I have interested in commiting aspgridview's data.
Posted
Comments
OriginalGriff 11-Mar-12 15:14pm    
Sorry - but we need a bit more than that.
What code are we talking about? C#? VB? Stored procedure?
When does the transaction start?
Why are you having a problem commiting?
Use the "Improve question" widget to edit your question and provide better information.
Paulo Augusto Kunzel 2-Apr-14 9:49am    
That is not a question, the sentence itself does little to show what is you concern.
Please edit it.

1 solution

Hi transactions usually works like this:

bool SaveValues(string name, string fathername, string email, string address)
{
bool result=false;
SqlConnection sqlconn = new SqlConnection();
SqlCommand command1 = new SqlCommand("insert into tabel1(name, fathername) values('" + name + "','" + fathername + "')");
SqlCommand command2 = new SqlCommand("insert into tabel2(email, address) values('" + email + "','" + address + "')";

SqlTransaction trx = sqlconn.BeginTransaction();
command1.Transaction = trx;
command2.Transaction = trx;

try
{
command1.ExecuteNonQuery();
command2.ExecuteNonQuery();
trx.Commit();
result=true;
}
catch (SqlException ex)
{
result=true;
trx.Rollback();
}
finally
{
//clean up resources
}
return result;
}

Best of luck.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900