CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2000
    Location
    Pune, India
    Posts
    34

    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...

  2. #2
    Join Date
    Jan 2000
    Location
    MO, USA
    Posts
    1,506

    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

  3. #3
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    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

  4. #4
    Join Date
    Jan 2000
    Location
    MO, USA
    Posts
    1,506

    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

  5. #5
    Join Date
    Feb 2000
    Location
    Pune, India
    Posts
    34

    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...

  6. #6
    Join Date
    Feb 2000
    Location
    Pune, India
    Posts
    34

    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...

  7. #7
    Join Date
    Jan 2000
    Location
    MO, USA
    Posts
    1,506

    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
  •  





Click Here to Expand Forum to Full Width

Featured