To : XunBaian(蓝水晶)Option Explicit Dim cnn As ADODB.ConnectionPrivate Sub Command1_Click() Set cnn = New ADODB.Connection cnn.Open "File Name=C:\test.udl" End Sub我按照你说的做的,配置好以后udl文件里就有了内容了,可是点击按钮却没有反应,还有就是那个连接字符串怎么传进vb里呢?有劳
oCnn = o.PromptEdit(oCnn) Debug.Print oCnn.ConnectionString End Sub
Option ExplicitPrivate Const INFINITE = &HFFFFFFFF Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long Private Const SEE_MASK_NOCLOSEPROCESS = &H40 Private Type SHELLEXECUTEINFO cbSize As Long fMask As Long hwnd As Long lpVerb As String lpFile As String lpParameters As String lpDirectory As String nShow As Long hInstApp As Long lpIDList As Long lpClass As String hkeyClass As Long dwHotKey As Long hIcon As Long hProcess As Long End Type Private Declare Function ShellExecuteEx Lib "shell32.dll" (SEI As SHELLEXECUTEINFO) As LongDim cnn As ADODB.ConnectionPrivate Sub Command1_Click() Dim SEI As SHELLEXECUTEINFO With SEI .cbSize = Len(SEI) .fMask = SEE_MASK_NOCLOSEPROCESS .hwnd = 0 .lpVerb = vbNullChar .lpFile = "C:\test.udl" .lpParameters = vbNullChar .lpDirectory = vbNullChar .nShow = 0 .hInstApp = 0 .lpIDList = 0 End With If ShellExecuteEx(SEI) <> 0 Then WaitForSingleObject SEI.hProcess, INFINITE '等待结束 CloseHandle SEI.hProcess End If Set cnn = New ADODB.Connection cnn.Open "File Name=C:\test.udl"End Sub
Dim cnn As ADODB.ConnectionPrivate Sub Command1_Click()
Set cnn = New ADODB.Connection
cnn.Open "File Name=C:\test.udl"
End Sub我按照你说的做的,配置好以后udl文件里就有了内容了,可是点击按钮却没有反应,还有就是那个连接字符串怎么传进vb里呢?有劳
我希望能够先调出数据链接属性窗口,在这里配置我的数据库。配置完了以后再打开udl文件取得连接,这样就比较灵活了。这样我该怎么做呢?
Dim o As New DataLinks
Dim oCnn As New Connection
oCnn = o.PromptNew
Debug.Print oCnn.ConnectionString
oCnn = o.PromptEdit(oCnn)
Debug.Print oCnn.ConnectionString
End Sub
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Const SEE_MASK_NOCLOSEPROCESS = &H40
Private Type SHELLEXECUTEINFO
cbSize As Long
fMask As Long
hwnd As Long
lpVerb As String
lpFile As String
lpParameters As String
lpDirectory As String
nShow As Long
hInstApp As Long
lpIDList As Long
lpClass As String
hkeyClass As Long
dwHotKey As Long
hIcon As Long
hProcess As Long
End Type
Private Declare Function ShellExecuteEx Lib "shell32.dll" (SEI As SHELLEXECUTEINFO) As LongDim cnn As ADODB.ConnectionPrivate Sub Command1_Click()
Dim SEI As SHELLEXECUTEINFO With SEI
.cbSize = Len(SEI)
.fMask = SEE_MASK_NOCLOSEPROCESS
.hwnd = 0
.lpVerb = vbNullChar
.lpFile = "C:\test.udl"
.lpParameters = vbNullChar
.lpDirectory = vbNullChar
.nShow = 0
.hInstApp = 0
.lpIDList = 0
End With
If ShellExecuteEx(SEI) <> 0 Then
WaitForSingleObject SEI.hProcess, INFINITE '等待结束
CloseHandle SEI.hProcess
End If Set cnn = New ADODB.Connection
cnn.Open "File Name=C:\test.udl"End Sub