帮我注释一个过程函数
Public Function TransactSQL(ByVal sql As String) As ADODB.Recordset
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strConnection As String
Dim strArray() As String
Set con = New ADODB.Connection
Set rs = New ADODB.Recordset
On Error GoTo TransactSQL_Error
strConnection = "provider=Microsoft.Jet.OLEDB.4.0;Data source = " & App.Path & "\table.mdb "
strArray = Split(sql)
con.Open strConnection
If StrComp(UCase$(strArray(0)), "select ", vbTextCompare) = 0 Then
rs.Open Trim$(sql), con, adOpenKeyset, adLockOptimistic
Set TransactSQL = rs
iflag = 1
Else
con.Execute sql
iflag = 1
End If
TransactSQL_Exit:
Set rs = Nothing
Set con = Nothing
Exit Function
TransactSQL_Error:
MsgBox "²éѯ´íÎó£º " & Err.Description
iflag = 2
Resume TransactSQL_Exit
End Function
不懂数据库,完全不懂这是干什么,就是每次改了数据库的内容的地方就会有调用到它,我只需要大致了解一下意思 当然都注释一下最好勒``呵呵!
谢谢勒``
[解决办法]
'处理SQL
Public Function TransactSQL(ByVal sql As String) As ADODB.Recordset
Dim con As ADODB.Connection '声明Connection对象
Dim rs As ADODB.Recordset '声明Recordset对象
Dim strConnection As String '连接字符串
Dim strArray() As String '声明数组
Set con = New ADODB.Connection
Set rs = New ADODB.Recordset
On Error GoTo TransactSQL_Error
strConnection = "provider=Microsoft.Jet.OLEDB.4.0;Data source = " & App.Path & "\table.mdb " '连接数据库的字符串
strArray = Split(sql) '将传递过来的SQL语句分割到数组
con.Open strConnection '打开连接
If StrComp(UCase$(strArray(0)), "select ", vbTextCompare) = 0 Then '如果是查询语句
rs.Open Trim$(sql), con, adOpenKeyset, adLockOptimistic '打开查询表
Set TransactSQL = rs ‘将Recordset对象返回
iflag = 1
Else
con.Execute sql '非查询语句,可能是update,delete等等
iflag = 1
End If
TransactSQL_Exit:
Set rs = Nothing
Set con = Nothing
Exit Function
TransactSQL_Error:
MsgBox "²éѯ´íÎó£º " & Err.Description
iflag = 2
Resume TransactSQL_Exit
End Function
[解决办法]
看书,不要直接拿不懂的代码来看,学习要有正确的方法才行.
[解决办法]
整个这个函数就是执行SQL语句,并且,如果是SELECT这样的会返回记录集的语句,就把记录集对象赋给这个函数,即返回一个结果记录集.如果是不会返回记录集结果的DML语句,则执行后不返回记录集,并在执行出现错误时捕获错误(否则将导致整个程序中断).