根据国家/地区下拉列表加载连接字符串[英] Load connection string depending on Country dropdown List

本文是小编为大家收集整理的关于根据国家/地区下拉列表加载连接字符串的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

大家好,

我的要求是这样的.
我在 web.config 中没有 connectionstring ,它们是按国家/地区设置的.
因此,当用户根据他的国家/地区登录时,connection string 只加载而不是全部加载.

而且我想这应该只在开始时出现一次.

请给我一些建议

感谢和问候

解决方案
您可以使用以下方法:
<br />
System.Configuration.ConfigurationManager.ConnectionStrings["YourConnectionString"].ConnectionString <br />

您可以使用带有 ExecuteReader 方法的 SqlCommand 对象执行选择命令,
见:http://msdn.microsoft.com/en-us/library/9kcbe65k.aspx
查看其他可用方法:http://msdn.microsoft.com/en-us/library/182ax5k8.aspx
例如,带有
的删除命令
<br />
ExecuteNonQuery()<br />

你好,

这会很容易,不是吗?你说你在配置文件中有一个连接字符串列表.所以每个连接字符串都有一个名字,对吧?
foreach (ConnectionStringSettings connectionString in ConfigurationManager.ConnectionStrings){Console.WriteLine(connectionString.Name);}

您可以从配置中提取这些名称并将其放在下拉列表中,也可以在连接字符串名称与您要显示的其他文本之间编写映射并在下拉列表中显示.后一种方法仅在连接字符串名称没有意义或其他情况下才有意义.

希望这会有所帮助,问候

本文地址:https://www.itbaoku.cn/post/1355977.html

问题描述

Hi Everybody,

My Requirement is in such a way that.
I have a no of connectionstring in web.config which are country wise set.
so when user has logged in depending on his country that no of connection string only to be loaded and not all.

And i suppose this should be only once at the start.

Please suggest me some thing

Thanks and regards

推荐答案

You can use following method:
<br />
System.Configuration.ConfigurationManager.ConnectionStrings["YourConnectionString"].ConnectionString <br />

You could execute select command using a SqlCommand object with the ExecuteReader method,
see: http://msdn.microsoft.com/en-us/library/9kcbe65k.aspx
Look into the other methods available: http://msdn.microsoft.com/en-us/library/182ax5k8.aspx
for example, a delete command with the
<br />
ExecuteNonQuery()<br />

Hey there,

It would be very easy, isn''t it? You said you got a list of connection strings in the config file. So each connection string is given a name, right?
foreach (ConnectionStringSettings connectionString in ConfigurationManager.ConnectionStrings)
{
  Console.WriteLine(connectionString.Name);
}

You can either pull these names from the config and put it in a drop down or you can write a mapping between the connection string names with some other text that you want to display and show that in the drop down. The latter method only makes sense when the connection string names doesn''t make sense or something.

Hope this helps, Regards