复制代码 代码如下:
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
//方法1
System.Data.DataTable table = System.Data.SqlClient.SqlClientFactory.Instance.CreateDataSourceEnumerator().GetDataSources();
GridView1.DataSource = table;
GridView1.DataBind();
//得到本机的
foreach (System.Data.DataRow row in table.Rows)
{
if (row[0].ToString().ToUpper().Equals(System.Net.Dns.GetHostName().ToUpper()))
{
Response.Write("<li>" + row[1]);
}
}
//方法2
//需要引用Microsoft.SqlServer.Smo.dll
GridView2.DataSource = Microsoft.SqlServer.Management.Smo.SmoApplication.EnumAvailableSqlServers(true);
GridView2.DataBind();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
<asp:GridView ID="GridView2" runat="server">
</asp:GridView>
</form>
</body>
</html>
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
//方法1
System.Data.DataTable table = System.Data.SqlClient.SqlClientFactory.Instance.CreateDataSourceEnumerator().GetDataSources();
GridView1.DataSource = table;
GridView1.DataBind();
//得到本机的
foreach (System.Data.DataRow row in table.Rows)
{
if (row[0].ToString().ToUpper().Equals(System.Net.Dns.GetHostName().ToUpper()))
{
Response.Write("<li>" + row[1]);
}
}
//方法2
//需要引用Microsoft.SqlServer.Smo.dll
GridView2.DataSource = Microsoft.SqlServer.Management.Smo.SmoApplication.EnumAvailableSqlServers(true);
GridView2.DataBind();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
<asp:GridView ID="GridView2" runat="server">
</asp:GridView>
</form>
</body>
</html>
标签:
本机,数据库,实例
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com
暂无“asp.net得到本机数据库实例的两种方法代码”评论...