高手求获得dsn列表的方法

jasmineou 2005-09-16 04:22:12
各位大侠帮帮我,是这样的,我现在要做一个关于execl的开发,首先要按一个按钮,然后打开一个窗口,在这个窗口里让用户选一个dsn,然后返回这个dsn的名字。所以想问问各位大侠怎样获得dsn列表
...全文
183 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
SuperZhou 2005-11-04
  • 打赏
  • 举报
回复
不错的方法
jam021 2005-09-21
  • 打赏
  • 举报
回复
northwolves 2005-09-16
  • 打赏
  • 举报
回复
The following is another site to view the solutions:

http://www.4guysfromrolla.com/webtech/011900-1.shtml
northwolves 2005-09-16
  • 打赏
  • 举报
回复
'Create a form and add a listbox called "list1",a commandbutton named "command1".
Private Declare Function SQLDataSources Lib "ODBC32.DLL" (ByVal henv&, ByVal fDirection%, ByVal szDSN$, ByVal cbDSNMax%, pcbDSN%, ByVal szDescription$, ByVal cbDescriptionMax%, pcbDescription%) As Integer
Private Declare Function SQLAllocEnv% Lib "ODBC32.DLL" (env&)
Const SQL_SUCCESS As Long = 0
Const SQL_FETCH_NEXT As Long = 1


Sub GetDSN()
Dim i As Integer
Dim sDSNItem As String * 1024
Dim sDRVItem As String * 1024
Dim sDSN As String
Dim sDRV As String
Dim iDSNLen As Integer
Dim iDRVLen As Integer
Dim lHenv As Long 'handle to the environment

On Error Resume Next
List1.AddItem "(None)"

'get the DSNs
If SQLAllocEnv(lHenv) <> -1 Then
Do Until i <> SQL_SUCCESS
sDSNItem = Space$(1024)
sDRVItem = Space$(1024)
i = SQLDataSources(lHenv, SQL_FETCH_NEXT, sDSNItem, 1024, iDSNLen, sDRVItem, 1024, iDRVLen)
sDSN = Left$(sDSNItem, iDSNLen)
sDRV = Left$(sDRVItem, iDRVLen)

If sDSN <> Space(iDSNLen) Then
List1.AddItem sDSN
cboDrivers.AddItem sDRV
End If
Loop
End If

List1.ListIndex = 0
End Sub


Private Sub Command1_Click()
GetDSN
End Sub

2,461

社区成员

发帖
与我相关
我的任务
社区描述
VBA(Visual Basic for Applications)是Visual Basic的一种宏语言,是在其桌面应用程序中执行通用的自动化(OLE)任务的编程语言。
社区管理员
  • VBA
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧