且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

根据国家/地区下拉列表加载连接字符串

更新时间:2023-08-17 17:09:34

您可以使用以下方法:
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