关于函数Execute的解释

jupiter97 2003-12-12 11:53:06
我最近用VB开发数据库的时候碰到一个函数:ExecuteSql,好像是个用户自定义的函数,有些地方我看不懂,你能不能帮我解释一下?
Public Function ConnectString() _
As String
'returns a DB ConnectString
ConnectString = "FileDSN=studentinfo.dsn;UID=sa;PWD=" '????????????
End Function
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
拜托了!
...全文
50 3 打赏 收藏 举报
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
yoki 2003-12-12
Public Function ConnectString() _
As String
'returns a DB ConnectString
ConnectString = "FileDSN=studentinfo.dsn;UID=sa;PWD=" '连接到服务器
End Function
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
  • 打赏
  • 举报
回复
hcj2002 2003-12-12
ConnectString = "FileDSN=studentinfo.dsn;UID=sa;PWD=" '连接一个数据库
  • 打赏
  • 举报
回复
lovepeacer 2003-12-12
up
  • 打赏
  • 举报
回复
相关推荐
发帖
数据库(包含打印,安装,报表)
加入

1199

社区成员

VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
申请成为版主
帖子事件
创建了帖子
2003-12-12 11:53
社区公告
暂无公告