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实例。
声明:本网页内容旨在传播知识,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。TEL:177 7030 7066 E-MAIL:11247931@qq.com