2 sinat 26793923 sinat_26793923 于 2015.05.28 11:52 提问

vb 连接access数据库路径问题

‘==================通过复制新建了个access数据库其中text.text放着CommonDialog1.FileName
Private Sub new_Click()
On Error GoTo Cancel
Dim FileName As String
Dim FileSystemObject As Object
CommonDialog1.Filter = "microsoft access 数据库(*.mdb)|*.mdb"
CommonDialog1.Action = 2
Text1.Text = CommonDialog1.FileName
Set FileSystemObject = CreateObject("Scripting.FileSystemObject")
FileSystemObject.CopyFile "C:\Users\admin\Desktop\tycs.mdb", Text1.Text
Cancel:
End Sub‘’‘查看已有该文件
’===============在连接数据库时
Dim cnn As New ADODB.Connection
Dim rs As New ADODB.Recordset
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = Text1.Text"
rs.Open "select * from YJCS", cnn, adOpenKeyset, adLockOptimistic
系统显示没有该路径
图片说明

1个回答

gamefinity
gamefinity   Rxr 2015.05.28 11:59
已采纳
 cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = Text1.Text"

改成

cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source =" & Text1.Text
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!