将appSettings值分配给String

时间:2017-02-28 07:55:55

标签: vb.net appsettings

我收到了错误消息。我正在尝试使用此appSettings连接到SQL SERVER。但是这段代码给出了一个错误。

警告6'公共共享ReadOnly属性AppSettings As System.Collections.Specialized.NameValueCollection'已过时:'此方法已过时,已被System.Configuration!System.Configuration.ConfigurationManager.AppSettings'取代。

enter image description here

`

Public Class clsDL

    'Fields - Data
    Private adp As SqlDataAdapter
    Private cmd As SqlCommand
    Private Cn As SqlConnection
    Private Shared db As clsDL
    Private dr As SqlDataReader
    Private ds As DataSet
    Private dt As DataTable
    Private gUserPwdSeed As Object = 10
    Private intIndex As Integer
    Private m_trans As SqlTransaction
    Private objConSettings As ConfigurationSettings
    Private strCnString As String
    Private strDatabase As String
    Private strPwd As String
    Private strServer As String
    Private strUID As String


    Private Sub Connect()
        Try
            Me.strServer = ConfigurationSettings.AppSettings("Server")
            Me.strDatabase = ConfigurationSettings.AppSettings("Database")
            Me.strUID = ConfigurationSettings.AppSettings("UID")

    End Sub`

1 个答案:

答案 0 :(得分:1)

使用警告中的建议。

Private Sub Connect()
    Try
        Me.strServer = System.Configuration.ConfigurationManager.AppSettings("Server")
        Me.strDatabase = System.Configuration.ConfigurationManager.AppSettings("Database")
        Me.strUID = System.Configuration.ConfigurationManager.AppSettings("UID")

End Sub`

我们从旧的代码库中采用了这种简单的方法,同时转换而不是重写,并且工作正常。