请教高手: 我的executeSql 公共模块为何总是报错???
各位大侠,我最近在学写vb+sql server2000 的应用程序。
在我的模块中我写了以下函数:
Public Function ExecuteSQL(ByValSQL As String, MsgString As String) _
As ADODB.Recordset
‘执行SQL语句,并返回记录集对象
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim sTokens() As String
‘异常处理
On Error GoTo ExecuteSQL_Error '
‘用Split函数产生一个包含各个子串的数组
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 ADODO.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.De脚本ion
Resume ExecuteSQL_Exit
End Function
但是运行是总是报错:用户定义类型未定义,请问这是什么原因。请高手指点!!谢谢!