请问各路vb数据库编程高手,偶虽然看懂了下面这个函数的意思,但是纳闷的事却来了,为什么它不用存储命令也能执行对数据库的操作,请问你们是怎么写对数据库进行操作函数的!
Public Function ExecuteSQL(ByVal SQL _ As String, MsgString As String) _ As ADODB.Recordset 'executes SQL and returns Recordset Dim cnn As ADODB.Connection Dim rst As ADODB.Recordset 定义记录集 Dim sTokens() As String On Error GoTo ExecuteSQL_Error 定义错误 sTokens = Split(SQL) Set cnn = New ADODB.Connection cnn.Open ConnectString If InStr("INSERT,DELETE,UPDATE", _ UCase$(sTokens(0))) Then cnn.Execute SQL MsgString = sTokens(0) & _ " query successful" Else Set rst = New ADODB.Recordset rst.Open Trim$(SQL), cnn, _ adOpenKeyset, _ adLockOptimistic 'rst.MoveLast 'get RecordCount Set ExecuteSQL = rst MsgString = "查询到" & rst.RecordCount & _ " 条记录 " End If ExecuteSQL_Exit: Set rst = Nothing Set cnn = Nothing Exit Function ExecuteSQL_Error: MsgString = "查询错误: " & _ Err.Description Resume ExecuteSQL_Exit End Function