vb 未发现数据源名称,连接不上。。求解决方法。 编译时总说:cnn.open conn 这里有问题
'函数ExecuteSQl()PublicFunctionExecuteSQL(ByValSQL_AsString,MsgstringAsString)_AsADODB....
'函数ExecuteSQl()
Public Function ExecuteSQL(ByVal SQL _
As String, Msgstring As String) _
As ADODB.Recordset
'此函数功能为执行SQL语句,返回记录集对象
Dim cnn As ADODB.Connection
Dim tst As ADODB.Recordset
Dim sTokens() As String
sTokens = Split(SQL)
Set cnn = New ADODB.Connection
cnn.Open CONN '打开与数据库的连接
If InStr("insert, delete, update", _
UCase$(sTokens(0))) Then '插入记录
cnn.Execute SQL
Msgstring = sTokens(0) & _
"查询成功"
Else
Set rst = New ADODB.Recordset
rst.Open Trim$(SQL), cnn, _
adOpenKeyset, _
adLockOptimistic
Set ExecuteSQL = rst
Msgstring = "查询" & rst.RecordsetCount & _
"条记录"
End If
ExecuteSQl_Exit: '切断与数据库的连接
Set rst = Nothing
Set cnn = Nothing
End Function 展开
Public Function ExecuteSQL(ByVal SQL _
As String, Msgstring As String) _
As ADODB.Recordset
'此函数功能为执行SQL语句,返回记录集对象
Dim cnn As ADODB.Connection
Dim tst As ADODB.Recordset
Dim sTokens() As String
sTokens = Split(SQL)
Set cnn = New ADODB.Connection
cnn.Open CONN '打开与数据库的连接
If InStr("insert, delete, update", _
UCase$(sTokens(0))) Then '插入记录
cnn.Execute SQL
Msgstring = sTokens(0) & _
"查询成功"
Else
Set rst = New ADODB.Recordset
rst.Open Trim$(SQL), cnn, _
adOpenKeyset, _
adLockOptimistic
Set ExecuteSQL = rst
Msgstring = "查询" & rst.RecordsetCount & _
"条记录"
End If
ExecuteSQl_Exit: '切断与数据库的连接
Set rst = Nothing
Set cnn = Nothing
End Function 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询