Insus.NET在演示中,是把找到的实例显示于DropDownList控件中。首先在.aspx拉一个DropDownList控件:
复制代码 代码如下:
Server: <asp:DropDownList ID="DropDownListInstance" runat="server"></asp:DropDownList>
然后在Page_Load事件写:
复制代码 代码如下:
View Code
protected void Page_Load(object sender, EventArgs e)
{
DataTable dataTable = SqlDataSourceEnumerator.Instance.GetDataSources();
foreach (DataRow dr in dataTable.Rows)
{
if (string.IsNullOrEmpty(dr["InstanceName"].ToString()))
this.DropDownListInstance.Items.Add(string.Concat(dr["ServerName"]));
else
this.DropDownListInstance.Items.Add(string.Concat(dr["ServerName"], "\\", dr["InstanceName"]));
}
}
运行结果,Insus.NET的手提电脑安装了SQL Server 2012和SQL Server 2008 R2,因此显示两个SQL Server实例。