[sql server7.0 or sql server2000] begin tran insert into product(productid, productname) values("0001", "keyboard") update product set price=12 where productid= "0002" if (@error>0) rollback else commit
[store procedure] create procedure product_save( as declare (@userid char(5), @location varchar(50), @returns int output ) begin tran update address set [email protected] where [email protected] if (@@error>0) begin @returns=-1 /* fail to update */ rollback end else @returns=0 /* succeed to update */ commit
return @returns
[web application in c#] int values; dbclass dbc=new dbclass(); // 使用new命令生成一个数据库类 values=dbc.updatedb("0001", "23 rain street"); //and call its function member to update record if (values==0) lable_message.text= "update successfully"; else lable_message.text= "sorry, can not update this record, please contact your dba."
try { mycommand.commandtext = "update address set location='23 rain street' where userid='0001'"; mycommand.executenonquery(); mytrans.commit(); console.writeline("record is udated."); } catch(exception e) { mytrans.rollback(); console.writeline(e.tostring()); console.writeline("sorry, record can not be updated."); } finally { myconnection.close(); }