Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将动态连接字符串传递到另一个Windows窗体(VB.NET)_Vb.net_Winforms_Connection String - Fatal编程技术网

将动态连接字符串传递到另一个Windows窗体(VB.NET)

将动态连接字符串传递到另一个Windows窗体(VB.NET),vb.net,winforms,connection-string,Vb.net,Winforms,Connection String,我正在创建一个windows应用程序,在应用程序启动时需要动态连接字符串(用户需要通过表单提供db凭据),输入连接凭据后用户重定向到新win表单 一切正常,但如何将动态连接传递到另一个表单 我试图将其保存到应用程序变量,但我无法(我认为它是只读的) 我还尝试将其保存到注册表,但无法检索值 还有其他选择吗?像写入和检索文本文件或XML的解析 谢谢这是获取和设置注册表值的方法: Public Function GetRegistryValue(ByVal KeyName As String, Opt

我正在创建一个windows应用程序,在应用程序启动时需要动态连接字符串(用户需要通过表单提供db凭据),输入连接凭据后用户重定向到新win表单 一切正常,但如何将动态连接传递到另一个表单

我试图将其保存到应用程序变量,但我无法(我认为它是只读的) 我还尝试将其保存到注册表,但无法检索值

还有其他选择吗?像写入和检索文本文件或XML的解析


谢谢

这是获取和设置注册表值的方法:

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%。因此,将其共享是一种简单的方法。