private void button1_Click(object sender, EventArgs e)
        {
            DataTable dataSources 
= SqlClientFactory.Instance.CreateDataSourceEnumerator().GetDataSources();

            DataColumn column 
= dataSources.Columns["InstanceName"];
            DataColumn column2 
= dataSources.Columns["ServerName"];

            DataRowCollection rows 
= dataSources.Rows;
            List
<string> Serverlist = new List<string>();
            
string array = string.Empty;
            
for (int i = 0; i < rows.Count; i++)
            {
                
string str2 = rows[i][column2] as string;
                
string str = rows[i][column] as string;
                
if (((str == null|| (str.Length == 0)) || ("MSSQLSERVER" == str))
                {
                    array 
= str2;
                    Console.WriteLine(array);
                }
                
else
                {
                    array 
= str2 + @"\" + str;
                    Console.WriteLine(array);
                }

                Serverlist.Add(array);
            }

            Serverlist.Sort();
        }
posted on 2011-03-17 14:19 Ying-er 阅读(393) 评论(0)  编辑  收藏 所属分类: .Net

只有注册用户登录后才能发表评论。


网站导航: