vb程序和access数据库连接的代码请大虾看看那里错了,运行时总说未定义
Public Function TransactSQL(ByVal sql As String) As ADODB.RecordsetDim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strConnection As String
Dim strArray() As String
Set con = New ADODB.Connection
Set rs = New ADODB.Recordset
On Error GoTo TransactSQL_Error
strConnection = "Provider=Microsoft.jet.oledb.4.0;Data Source=" & App.Path & "\DB\StuData.mdb"
strArray = Split(sql)
con.Open strConnection
If StrComp(UCase$(strArray(0)), "select", vbTextCompare) = 0 Then
rs.Open Trim$(sql), con, adOpenKeyset, adLockOptimistic
Set TransactSQL = rs
iflag = 1
Else
con.Execute sql
iflag = 1
End If
TransactSQL_Exit:
Set rs = Nothing
Set con = Nothing
Exit Function
TransactSQL_Error:
MsgBox "查询错误:" & Err.Description
iflag = 2
Resume TransactSQL_Exit
End Function
--------------------编程问答-------------------- http://download.csdn.net/detail/veron_04/3827200 --------------------编程问答-------------------- 谢谢 这个已经解决了 --------------------编程问答-------------------- 我觉得你strArray = Split(sql)
con.Open strConnection
If StrComp(UCase$(strArray(0)), "select", vbTextCompare) = 0 Then
这里面应该是出问题了.
你在rs.Open Trim$(sql), con, adOpenKeyset, adLockOptimistic前面加个断点
然后运行到这里的时候
debug.pting Trim$(sql) 看看里面的sql语句到底是怎么回事吧. --------------------编程问答--------------------
补充:VB , 数据库(包含打印,安装,报表)