2017-02-21 14 views
-1

私はvb.netでパブリッククラスを持つパブリッククラスを持っています。コンストラクタは実行されていないようです。私は中断しないコンストラクタにブレークポイントを持っています。また、データベースを更新すると、新しい値が辞書に表示されません。実行するパブリッククラスのコンストラクタを取得する方法

Public Class SkywalkerPolicy 

Public Shared CustomPolicies As Dictionary(Of String, String) 

Shared Sub New() 
    CustomPolicies = New Dictionary(Of String, String) 
    Dim bvin As String = String.Empty 
    Dim title As String = String.Empty 
    Dim poldescr As String = String.Empty 
    Dim dtResult As New DataTable("Result") 
    dtResult.Locale = System.Globalization.CultureInfo.InvariantCulture 
    Dim request As New DataRequest 

    request.Command = "sky_PolicyDictionary_s" 
    request.CommandType = CommandType.StoredProcedure 

    request.Transactional = False 
    Dim result As DataSet 
    result = SqlDataHelper.ExecuteDataSet(request) 

    If Not result Is Nothing Then 
     If result.Tables.Count() > 0 Then 
      dtResult = result.Tables(0) 
      For Each row In dtResult.AsEnumerable 
       bvin = row.Item(1) 
       title = row.Item(0) 
       poldescr = row.Item(2) 
       If CustomPolicies.ContainsKey(title) Then 
        CustomPolicies(title) += poldescr 
       Else 
        CustomPolicies.Add(title, poldescr) 
       End If 
      Next 
     End If 
    End If 

End Sub 
End Class 

辞書にアクセスすると、データに行った変更は表示されません。

Dim pol As String = SkywalkerPolicy.CustomPolicies("Orders and Shipping Details") 

どのように私は動作するようにコンストラクタを得ることができますか?

私はそれを使用する前に辞書を初期化する複製を追加する必要がありますか?

おかげ

+0

あなたは例えば...どこかにオブジェクトとしてクラスをインスタンス化しています。プライベートMyPolicy =新しいSkywalkerPolicy? –

+0

は、新しい方法が –

+0

を実行する必要があり、私はただの文字列= MyPolicy.CustomPolicies(「受注及び発送詳細」)として暗いMYPOLICY =新SkywalkerPolicy 薄暗いPOL \t \t \tように私は、共有メンバーのアクセスも、一定のメンバー、列挙型のメンバを取得することを試みましたまたはインスタンスを介してネストされた型。修飾表現は評価されません。 – Roger

答えて

-1

は私が辞書にアクセスする前に呼び出すだけ更新ルーチンと回避策を持っています。しかし、なぜ私がコンストラクターを踏んで行くことができないのかはまだ分かりません。だから誰でも元の質問に答えることができれば、私は更新を感謝します。ありがとうございました。

Public Class SkywalkerPolicy 

Public Shared CustomPolicies As Dictionary(Of String, String) 

Shared Sub New() 
    CustomPolicies = New Dictionary(Of String, String) 
    Dim bvin As String = String.Empty 
    Dim title As String = String.Empty 
    Dim poldescr As String = String.Empty 
    Dim dtResult As New DataTable("Result") 
    dtResult.Locale = System.Globalization.CultureInfo.InvariantCulture 
    Dim request As New DataRequest 

    request.Command = "sky_PolicyDictionary_s" 
    request.CommandType = CommandType.StoredProcedure 

    request.Transactional = False 
    Dim result As DataSet 
    result = SqlDataHelper.ExecuteDataSet(request) 

    If Not result Is Nothing Then 
     If result.Tables.Count() > 0 Then 
      dtResult = result.Tables(0) 
      For Each row In dtResult.AsEnumerable 
       bvin = row.Item(1) 
       title = row.Item(0) 
       poldescr = row.Item(2) 
       If CustomPolicies.ContainsKey(title) Then 
        CustomPolicies(title) += poldescr 
       Else 
        CustomPolicies.Add(title, poldescr) 
       End If 
      Next 
     End If 
    End If 

End Sub 

Public Shared Sub UpdateDictionary() 
    CustomPolicies.Clear() 
    Dim bvin As String = String.Empty 
    Dim title As String = String.Empty 
    Dim poldescr As String = String.Empty 
    Dim dtResult As New DataTable("Result") 
    dtResult.Locale = System.Globalization.CultureInfo.InvariantCulture 
    Dim request As New DataRequest 

    request.Command = "sky_PolicyDictionary_s" 
    request.CommandType = CommandType.StoredProcedure 

    request.Transactional = False 
    Dim result As DataSet 
    result = SqlDataHelper.ExecuteDataSet(request) 

    If Not result Is Nothing Then 
     If result.Tables.Count() > 0 Then 
      dtResult = result.Tables(0) 
      For Each row In dtResult.AsEnumerable 
       bvin = row.Item(1) 
       title = row.Item(0) 
       poldescr = row.Item(2) 
       If CustomPolicies.ContainsKey(title) Then 
        CustomPolicies(title) += poldescr 
       Else 
        CustomPolicies.Add(title, poldescr) 
       End If 
      Next 
     End If 
    End If 
End Sub 

エンドクラス

+0

あなたはこのクラスのRogerの使い方をより具体的に理解する必要があります。どのように使用したいかによって実際には2つの異なる答えがあります。しかし、私たちはあなたの心を読むことができません。 –

+0

私はこのクラスを使ってポリシーの辞書を定義しています。この辞書をWebサイトに表示するためにアクセスできます。このWebサイトの管理者の1人として、私または他の管理者がポリシーを更新したり、ポリシーの下に新しいブロックを追加することができます。私はなぜコンストラクタに入れられたブレークポイントが決して壊れないのか尋ねています。 – Roger

+0

いつログオフしてログオンし直すか、Webサイトを閉じてからVisual Studioから別のデバッグセッションを実行すると、コンストラクタを実際に実行する必要があります。新しいデータ変更は決して拾われません。だから私は回避策を考え出した。私はまだウェブプログラミングの面白さを学んでおり、これがポストに興味深い問題だと思っていました。私は、私が理解していなかったプロセスについての投稿に対する批判の負荷を期待していなかった。私はデータを変更したことをコンストラクタがピックアップして辞書を読み込んでいないことを明確にしたと思いました。 – Roger

関連する問題