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

查看:72
本文介绍了根据国家/地区下拉列表加载连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我的要求是这样的.
我在国别设置的web.config中没有 connectionstring .
因此,当用户根据自己的国家/地区登录时,连接字符串中的任何一个都不会被加载,也不会全部被加载.

而且我想这应该一开始就只有一次.

请给我建议一些东西

感谢和问候

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 />


您可以使用带有ExecuteReader方法的SqlCommand对象执行选择命令,
请参阅:http://msdn.microsoft.com/en-us/library/9kcbe65k.aspx
查看其他可用方法:http://msdn.microsoft.com/zh-cn/library/182ax5k8.aspx
例如,带有
的删除命令


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


这篇关于根据国家/地区下拉列表加载连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆