Bruce Cohen
4/5/2002 5:52:00 PM
Hello,
I am trying to write an application in C#. Does anyone
know how I can populate a list box with all available DSNs
within the PC?
I have seen examples under VB6 using API calls as follows:
Declare Function SQLAllocEnv Lib "odbc32.dll" (env As
Long) As Integer
Declare Function SQLDataSources Lib "odbc32.dll" (ByVal
henv&, ByVal fDirection%, ByVal szDSN$, ByVal cbDSNMax%,
pcbDSN%, ByVal szDescription$, ByVal cbDescriptionMax%,
pcbDescription%) As Integer
Global Const SQL_FETCH_NEXT As Integer = 1
Sub GetDSNsAndDrivers(myForm As Form)
On Error Resume Next
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
If SQLAllocEnv(lHenv) <> -1 Then
Do Until i <> 0
sDSNItem = Space(1024)
sDRVItem = Space(1024)
i = SQLDataSources(lHenv, SQL_FETCH_NEXT,
sDSNItem, 1024, iDSNLen, sDRVItem, 1024, iDRVLen)
sDSN = VBA.Left(sDSNItem, iDSNLen)
sDRV = VBA.Left(sDRVItem, iDRVLen)
If sDSN <> Space(iDSNLen) Then
myForm.cboDSNList.AddItem sDSN
End If
Loop
End If
End Sub
However, is there anyway it can be done in C# without
making API call?
Thanks for any help.
Bruce.