|
-
February 1st, 2000, 08:30 AM
#1
How to fill a combobox with available DSN entries?
How to fill a combobox with available DSN entries?
Initiative is to success what a lighted match is to a candle...
-
February 1st, 2000, 12:54 PM
#2
Re: How to fill a combobox with available DSN entries?
This is some code that I use to get a list of DSNs and also a list of drivers...
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 GetDSNsAndDrivers()
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
cboDSNList.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
cboDSNList.AddItem sDSN
cboDrivers.AddItem sDRV '---optional - driver value returned
End If
Loop
End If
'remove the dups
If cboDSNList.ListCount > 0 then
With cboDrivers
If .ListCount > 1 then
i = 0
While i < .ListCount
If .List(i) = .List(i + 1) then
.RemoveItem (i)
else
i = i + 1
End If
Wend
End If
End With
End If
cboDSNList.ListIndex = 0
End Sub
If you don't want the drivers list, then just don't do anything with the data that comes back.
Hope this helps,
John
John Pirkey
MCSD
www.ShallowWaterSystems.com
John Pirkey
MCSD (VB6)
http://www.stlvbug.org
-
February 1st, 2000, 04:47 PM
#3
Re: How to fill a combobox with available DSN entries?
That's excellent - would you like me to post it onto the site for you ?
Chris Eastwood
CodeGuru - the website for developers
http://codeguru.developer.com/vb
-
February 1st, 2000, 05:59 PM
#4
Re: How to fill a combobox with available DSN entries?
If you feel that its worthy, then be my guest.
Thanks for the compliment.
John
John Pirkey
MCSD
www.ShallowWaterSystems.com
John Pirkey
MCSD (VB6)
http://www.stlvbug.org
-
February 2nd, 2000, 05:28 AM
#5
Re: How to fill a combobox with available DSN entries?
Yes, definitely.
I am obliged
Thanks in advance
Initiative is to success what a lighted match is to a candle...
-
February 2nd, 2000, 05:33 AM
#6
Re: How to fill a combobox with available DSN entries?
Thanks for helping me out...
How to become ur guest? i have tried visiting the web site and haven't seen any guest book....
Bye Bye
Initiative is to success what a lighted match is to a candle...
-
February 2nd, 2000, 11:34 AM
#7
Re: How to fill a combobox with available DSN entries?
I don't currently have a guest book at that location. To be honest, I haven't updated that site recently. Most of my time has been spent working on www.stlvbug.org. Just the visit to my site was thanks enough.
Let me know if I can help you out with anything else.
John
John Pirkey
MCSD
www.ShallowWaterSystems.com
John Pirkey
MCSD (VB6)
http://www.stlvbug.org
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|