使用标签或变量的VB6 MS访问驱动程序连接字符串

时间:2013-11-30 15:05:00

标签: vb6

默认MS访问连接字符串是

connection = "Driver={Microsoft Access Driver (*.mdb)};" & _
    "dbq=Database1.mdb;" & _
    "DefaultDir=E:\somepath;" & _
    "uid=Admin;Pwd=;"

我希望使用label来获取数据库路径信息

connection = "Driver={Microsoft Access Driver (*.mdb)};" & _
    Chr(34) & "dbq=" & lblF.Caption & ";" & Chr(34) & _
    Chr(34) & "DefaultDir=" & LocL.Caption & ";" & Chr(34) & _
    "uid=Admin;Pwd=;"

但它失败了:(

1 个答案:

答案 0 :(得分:0)

删除所有Chr()调用。您不需要在此连接字符串中插入任何双引号。

connection = "Driver={Microsoft Access Driver (*.mdb)};" & _
             "dbq=" & lblF.Caption & ";" & _
             "DefaultDir=" & LocL.Caption & ";" & _
             "uid=Admin;Pwd=;"