vb初学者

cymandhxl 2006-03-14 03:46:31
Public Shared Function DeleteUserReportAuthorization(ByVal index As Integer, Optional ByVal trans As SqlTransaction = Nothing) As Integer
Dim retVal As Integer
Dim conPortal As SqlConnection
Dim sqlCmd As SqlCommand

Dim outerTrans As Boolean

If trans Is Nothing Then
outerTrans = False

conPortal = New SqlConnection(HerpData.ConnectionString(HerpSubSystems.HerpCM))
sqlCmd = New SqlCommand("UserReportAuthorizationsDeleteUserReportAuthorization", conPortal)
Else
outerTrans = True

conPortal = trans.Connection
sqlCmd = New SqlCommand("UserReportAuthorizationsDeleteUserReportAuthorization", conPortal, trans)
End If

sqlCmd.CommandType = CommandType.StoredProcedure

sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int).Direction = ParameterDirection.ReturnValue

sqlCmd.Parameters.Add("@ura_id", index)

If conPortal.State = ConnectionState.Closed Then
conPortal.Open()
End If

Try
sqlCmd.ExecuteNonQuery()
Catch ex As Exception
If outerTrans = False Then conPortal.Close()
Return -1
End Try

retVal = Fix(sqlCmd.Parameters("@RETURN_VALUE").Value)
If outerTrans = False Then conPortal.Close()
Return retVal
End Function


Optional ByVal trans As SqlTransaction = Nothing) As Integer
这句是什么意思,为什么要加上事物来做为参数
...全文
105 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
copico 2006-03-15
  • 打赏
  • 举报
回复
Optional 关键字指示在调用过程时可以省略过程参数。
夜雨悠扬 2006-03-14
  • 打赏
  • 举报
回复
Optional 是可选参数
这个东西的意思应该是如果外边有数据库连接并且打开事务的时候,为了在函数里面也可以访问数据库而作的
ALong_Yue 2006-03-14
  • 打赏
  • 举报
回复
同意楼上的回答。
在调用DeleteUserReportAuthorization的时候,如果不给trans传值,会使用默认值NOTHING。
yz1199 2006-03-14
  • 打赏
  • 举报
回复
这个表示可选参数,也就是在调用这个函数时,trans这个参数可以不传

16,555

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧