天猫买药 提交需求:哪位VB大哥帮忙逐行解释该程序小弟不胜感激!!

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/12 12:09:26
Public Function ExecuteSQL(ByVal SQL As String, MsgString As String) "As ADODB.Recordset
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim sTokens() As String
SQL = Replace(SQL, vbCrLf, vbNullString)
On Error GoTo ExecuteSQL_Error
sTokens = Split(SQL)
Set cnn = New ADODB.Connection
cnn.ConnectionString = (ConnectString)
cnn.Open
If InStr("INSERT,DELETE,UPDATE", UCase$(sTokens(0))) Then
cnn.Execute SQL
MsgString = sTokens(0) & " query successful"
Else
Set rs = New ADODB.Recordset
With rs
.ActiveConnection = cnn
.CursorLocation = adUseClient
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open SQL
End With
Set ExecuteSQL = rs
MsgString = "查询到" & ExecuteSQL.RecordCount & " 条记录 "
End If
ExecuteSQL_Exit:
Set rst = Nothing
Set cnn = Nothing
Exit Function
ExecuteSQL_Error:
MsgString = "查询错误: " & Err.Description
Resume ExecuteSQL_Exit
End Function

Public Function ExecuteSQL(ByVal SQL As String, MsgString As String) "As ADODB.Recordset
Dim cnn As ADODB.Connection '声明连接类
Dim rst As ADODB.Recordset '声明rst为recordset
Dim sTokens() As String 's声明sTo...为字符串类变量
SQL = Replace(SQL, vbCrLf, vbNullString) '定义sql语句 其中replace为替代函数,具体用法自己可以查
On Error GoTo ExecuteSQL_Error '错误处理,如果出错
sTokens = Split(SQL) 's把SQL字符串分割
Set cnn = New ADODB.Connection '新建conn连接
cnn.ConnectionString = (ConnectString)
cnn.Open 'conn开启
If InStr("INSERT,DELETE,UPDATE", UCase$(sTokens(0))) Then
cnn.Execute SQL
MsgString = sTokens(0) & " query successful"
Else
Set rs = New ADODB.Recordset
With rs
.ActiveConnection = cnn
.CursorLocation = adUseClient
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open SQL
End With
Set ExecuteSQL = rs
MsgString = "查询到" & ExecuteSQL.RecordCount & " 条记录 "
End If
ExecuteSQL_Exit:
Set rst = Nothing
Set cnn = Nothing
Exit Function
ExecuteSQL_Error:
MsgString = "查询错误: " & Err.Description
Resume ExecuteSQL_Exit
End Function

先翻译一半,一会继续:-)

晕~都看不懂