try-catch-finally 两个重点

 Try          

   con_brmis = Css2DataAccess.GetConnection(Nothing, "css2")            

tran_All = con_brmis.BeginTransaction("tran_All")            

Css2DataAccess.ExecuteNonQuery(tran_All, CommandType.Text, Sql_str)

 '將數據傳輸到供應商管理系統中間數據庫 

  Css2DataAccess.ExecuteNonQuery(tran_All, CommandType.StoredProcedure, "SP_ZDF_Master", aPara_Sub)

      ErrorMsg.Text = Resources.CommonLan.UpdateStockSuc           '如果前面执行失败,则直接跳到catch 模块 ,而不再执行以下的代码

   tran_All.Commit()        

Catch ex As Exception            

ErrorMsg.Text = ex.Message + "<br>" + Resources.CommonLan.TryOrAsk           

  tran_All.Rollback()        

Finally            

  con_brmis.Close()         '无论前面是否报异常,都 将执行此模块的语句 ,保证了资源的回收

  End Try

posted @ 2012-06-25 10:43  withoutaword  阅读(147)  评论(0编辑  收藏  举报