Dear Merline Martina,
Here is a sample code which explains about the database transactions in a
web service.
[Web Method]
public string adduser( string UserName, string UserPassword)
{
string uname,upassword;
uname=UserNmae;
upassword=userPassword;
string mycon=â€Intial Catalog=test;Data Source= johnpaul\DBTEST; Integrated
security =SSPIâ€;
//declare a sql connection by building a object named myconnection
SqlConnection mysqlConnection =new SqlConnection(mycon);
// declare sql command by using a object named mycommand
SqlCommand mysqlCommand = new SqlCommand();
// using sql transaction class
SqlTransaction myTrans;
// Open the connection.
mysqlConnection.Open();
// Assign the connection property.
mysqlCommand.Connection = mysqlConnection;
// Begin the transaction.
myTrans = myConnection.BeginTransaction();
// Assign transaction object for a pending local transaction
mysqlCommand.Transaction = myTrans;
try
{
// Insert the user record.
mysqlCommand.CommandText = "Insert into useraccount VALUES
('"+uname+"','"+ufamily+"')";
mysqlCommand.ExecuteNonQuery();
// pass the data .transaction complete
myTrans.Commit();
return "transaction completed";
}
catch(Exception e)
{
// transaction cancel
myTrans.Rollback();
return e.ToString()+"transaction abort";
}
}
Rgds,
John Paul. A
[quoted text, click to view] "Merline Martina" wrote:
> Can anyone tell me how to work with database transactions in a web service.
> Can anyone please give me a sample code.
> --
> Cool!!