Can we declare variables in the #39;app.config#39; file?(我们可以在“app.config文件中声明变量吗?)
问题描述
我有一个需要连接到 SQL Server 的表单,我有一个用于选择数据库列表和执行主键检查等操作的下拉菜单.
I have a form which needs to get connected to SQL Server, and I have a drop down for selecting the list of databases and perform operations like primary key checking, etc.
但目前我的连接字符串如下所示:
But presently my connection string looks like this:
SqlConnection sConnection = new SqlConnection("Server=192.168.10.3;DataBase=GoalPlanNew;User Id=gp;Password=gp");
但是除了给定的数据库之外,我还需要将它作为变量,以便我可以将它连接到我从下拉列表中选择的数据库.
But apart from the given database, I need to take it variable, so that I can connect it to the database I select from the dropdown.
我该怎么做?
推荐答案
嗯,你可以像这样声明你的变量
Hmm you can declare your variables like this
<appSettings>
<add key="SmtpServerHost" value="********" />
<add key="SmtpServerPort" value="25" />
<add key="SmtpServerUserName" value="******" />
<add key="SmtpServerPassword" value="*****" />
</appSettings>
读起来像
string smtpHost = ConfigurationManager.AppSettings["SmtpServerHost"];
int smtpPort = Convert.ToInt32(ConfigurationManager.AppSettings["SmtpServerHost"]);
这篇关于我们可以在“app.config"文件中声明变量吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:我们可以在“app.config"文件中声明变量吗?
基础教程推荐
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
