我希望当我用文件填充文本框以更改app配置文件中的connectionstring中的数据时 任何人都可以为此提供示例 提前致谢Hi guysI have an application with SQL EXPRESS database.I have created a form to connect to SQL SERVER with four textboxes.textbox1 = servertextbox2 = database nametextbox3 = usertextbox4 = passI want when I fill the textboxes with data to change the data in connectionstring in app config filecan anyone give examples for thisThanks in advance推荐答案使用[ApplicationNameSpace.Properties.Settings.Default.ConnectionStringName]访问app.config文件中的Connection字符串。 但我很担心,因为看起来你无法访问value属性来改变它,而只能读取它。 为什么不把你的connectionString保存到注册表?在那里你可以随时编辑/阅读Use [ApplicationNameSpace.Properties.Settings.Default.ConnectionStringName] to access your Connection string in the app.config file.But am worried, because it seems that there is no way you can access the value property in order to change it, instead you can only read the value.Why don''t you instead save your connectionString to the registry? There you can edit/read it any time you wantusing Microsoft.Win32;//Writing to the registrystring ConnectionStringValues = TextBoxServer; + TextBoxUID;...; RegistryKey regkey = Registry.CurrentUser.CreateSubKey(@"Software\YourSoftwareName\RegistryKey");regkey.SetValue("ConnectionStringName", "ConnectionStringValues");//Reading from the registry (Getting your connectionString)RegistryKey regkey = Registry.CurrentUser.CreateSubKey(@"Software\YourSoftwareName\RegistryKey");regkey.GetValue("ConnectionStringName").ToString(); / * 别忘了先在注册表中创建注册表项 打开运行 - >输入命令regedit, 展开HKEY_CURRENT_USER, 找到并右键单击Software文件夹, 新 - >键(将其命名为ConnectionStringName或您喜欢的任何其他名称), 右键单击您创建的文件夹并选择:新建 - > gt;字符串值 您可以保留值字段为空白或使用当前连接字符串初始化 还要记住在构建安装程序时包含这些注册表 问候 * //*Don''t forget to create the registry key first in the registryOpen Run -> Type in the command regedit,Expand HKEY_CURRENT_USER,Locate and RightClick on Software folder,New -> Key (Name it ConnectionStringName or any other name you prefer),Right Click on the folder you created and choose: New ->String ValueYou can leave the value field blank or initialize it with your current connection stringAlso remember to include these registries when building your installerRegards*/请阅读:连接字符串和配置文件 [ ^ ] LINQ to XML:在app.config中更改connectionString [ ^ ] CP网站上的相关文章: 将连接字符串保存到app.config [ ^ ] 如何使用编码在App.config中添加/更改连接字符串 [ ^ ]Please, read this: Connection Strings and Configuration Files[^]LINQ to XML : Changing connectionString in app.config[^]Related articles on CP site:Saving Connection Strings to app.config[^]How to Add/Change Connection String in App.config with Coding[^] 这篇关于如何更改应用程序配置文件中的连接字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-23 23:27