2012-02-20 75 views
0

我正在創建一個Windows應用程序,該應用程序需要啓動應用程序中的動態連接字符串(用戶需要通過表單提供數據庫憑據),輸入連接憑證後,用戶重定向以新的勝利形式 一切工作正常,但我怎麼能通過我的動態連接到另一種形式。將動態連接字符串傳遞給另一個Windows窗體(VB.NET)

我試圖將它保存到應用程序變量,但我不能(我認爲它的只讀) 另外我試着將它保存到註冊表,但無法檢索值。

還有其他選擇嗎?就像寫&檢索ConString到一個文本文件或XML

感謝

+0

只有一個連接字符串。因此使其成爲共享是一種簡單的方法。 – 2012-02-20 15:59:12

回答

0

這如何可以獲取和設置註冊表值:

Public Function GetRegistryValue(ByVal KeyName As String, Optional ByVal DefaultValue As Object = Nothing) As Object 
     Dim res As Object = Nothing 
     Try 
      Dim k = My.Computer.Registry.CurrentUser.OpenSubKey("Software\YourAppName", True) 
      If k IsNot Nothing Then 
       res = k.GetValue(KeyName, DefaultValue) 
      Else 
       k = My.Computer.Registry.CurrentUser.CreateSubKey("Software\YourAppName") 
      End If 
      If k IsNot Nothing Then k.Close() 
     Catch ' ex As Exception 
      'PromptMsg(ex) 
     End Try 
     Return res 
End Function 

Public Sub SetRegistryValue(ByVal KeyName As String, ByVal _Value As Object) 
     Try 
      Dim k = My.Computer.Registry.CurrentUser.OpenSubKey("Software\YourAppName", True) 
      If k IsNot Nothing Then 
       k.SetValue(KeyName, _Value) 
      Else 
       k = My.Computer.Registry.CurrentUser.CreateSubKey("Software\YourAppName") 
       k.SetValue(KeyName, _Value) 
      End If 
      If k IsNot Nothing Then k.Close() 
     Catch ' ex As Exception 
      'PromptMsg(ex) 
     End Try 
End Sub 

它的工作100%,如果你請註明此答案Right

相關問題