请各位高手给我理解一下这些程序,谢谢了啊
请各位高手给我理解一下这些程序,谢谢了啊Public Function ExecuteSQL(ByVal sql As String) As ADODB.Recordset
Dim mycon As ADODB.Connection
Dim rst As ADODB.Recordset
Set mycon = New ADODB.Connection
mycon.ConnectionString = connstring
mycon.Open
Dim stokens() As String
On Error GoTo exectuesql_error
stokens = Split(sql)
If InStr("INSER,DELETE,UPDATE", UCase(stokens(0))) Then
mycon.Execute sql
Else
Set rst = New ADODB.Recordset
rst.Open Trim(sql), mycon, adOpenKeyset, adLockOptimistic
Set ExecuteSQL = rst
End If
exectuesql_exit:
Set rst = Nothing
Set mycon = Nothing
Exit Function
exectuesql_error:
Resume exectuesql_exit
End Function
--------------------编程问答-------------------- 通用SQL执行方法:
dim sqlString as string ="SQL语句"
对象.ExecuteSQL(sqlString)
--------------------编程问答-------------------- 我是才开始学习VB的啊。我看不懂这个。能说清楚点吗?谢谢了啊 --------------------编程问答-------------------- Public Function ExecuteSQL(ByVal sql As String) As ADODB.Recordset
Dim mycon As ADODB.Connection
Dim rst As ADODB.Recordset
Set mycon = New ADODB.Connection
mycon.ConnectionString = connstring
mycon.Open
Dim stokens() As String
On Error GoTo exectuesql_error '如果出错跳到exectuesql_error:
stokens = Split(sql) '把sql中的字符串存入stokens数组
If InStr("INSER,DELETE,UPDATE", UCase(stokens(0))) Then '如果sql中的第一个单词是INSER,DELETE,UPDATE
mycon.Execute sql '执行sql语句
Else '否则执行查询语句返回数据集
Set rst = New ADODB.Recordset
rst.Open Trim(sql), mycon, adOpenKeyset, adLockOptimistic
Set ExecuteSQL = rst
End If
exectuesql_exit:
Set rst = Nothing
Set mycon = Nothing
Exit Function
exectuesql_error:
Resume exectuesql_exit
End Function --------------------编程问答-------------------- 谢谢啊.现在我知道了 --------------------编程问答-------------------- 3楼说的很明白
补充:.NET技术 , VB.NET