获取DataSource名称和数据 [英] Get DataSource Name and Data

查看:670
本文介绍了获取DataSource名称和数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!



我设法从注册表中获取DSN。但数据列无法检索。有人能帮我吗?下面是我找到ODBC值的代码。



Hi!

I manage to get the DSN from registry. But the column for data unable to retrieve. Can someone help me? Below are my code to find the value of ODBC.

Private Sub GetDSNDetails()
       Dim dsnNames As New List(Of String)
       Dim reg As Microsoft.Win32.RegistryKey = Registry.LocalMachine.OpenSubKey("Software")
       If reg IsNot Nothing Then
           reg = reg.OpenSubKey("ODBC")
           If reg IsNot Nothing Then
               reg = reg.OpenSubKey("ODBC.INI")
               If reg IsNot Nothing Then
                   reg = reg.OpenSubKey("ODBC Data Sources")
                   If reg IsNot Nothing Then
                       For Each dsn As String In reg.GetValueNames
                           dsnNames.Add(dsn)
                       Next
                   End If
               End If

           End If
       End If

       For Each Name As String In dsnNames
           TextBox1.AppendText("DataSource Name: " & Name & Environment.NewLine)
       Next Name
   End Sub





我需要来自注册表的ODBC数据源的2个值。这就是名称和数据作为图像[ ^ ]

推荐答案





试试这个,

Hi,

Try this one,
Dim dsnNames As New List(Of String)
Dim reg As Microsoft.Win32.RegistryKey =      Registry.LocalMachine.OpenSubKey("Software")
If reg IsNot Nothing Then
    reg = reg.OpenSubKey("ODBC")
    If reg IsNot Nothing Then
        reg = reg.OpenSubKey("ODBC.INI")
        If reg IsNot Nothing Then
            reg = reg.OpenSubKey("ODBC Data Sources")
            If reg IsNot Nothing Then
                For Each dsn As String In reg.GetValueNames
                    dsnNames.Add(dsn & "-" & reg.GetValue(dsn))
                Next
            End If
        End If

    End If
End If

For Each Name As String In dsnNames
    TextBox1.AppendText("DataSource Name: " & Name & Environment.NewLine)
Next Name





希望这可以帮到你!!



hope this may help you!!


这篇关于获取DataSource名称和数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆