[Store Procedure] CREATE PROCEDURE PRODUCT_SAVE( AS DECLARE (@USERID CHAR(5), @LOCATION VARCHAR(50), @RETURNS INT OUTPUT ) BEGIN TRAN UPDATE ADDRESS SET LOCATION=@LOCATION WHERE USERID=@USERID IF (@@ERROR>0) BEGIN @RETURNS=-1 /* Fail to Update */ ROLLBACK END ELSE @RETURNS=0 /* Suclearcase/" target="_blank" >cceed 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." |
[Web Applicaion in C#] SqlConnection myConnection = new SqlConnection("Data Source=localhost;Initial Catalog=Northwind;Integrated Security=SSPI;"); myConnection.Open(); SqlTransaction myTrans = myConnection.BeginTransaction(); //使用New新生成一个事务 SqlCommand myCommand = new SqlCommand(); myCommand.Transaction = myTrans; 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(); } |