时间:2021-07-01 10:21:17 帮助过:40人阅读
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实例。