这篇文章介绍了asp
net得到本机数据库实例的两种方法代码
有需要的朋友可以参考一下
复制代码 代码如下:
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "//WC//DTD XHTML Transitional//EN" "
<script runat="server">
protected void Page_Load(object sender EventArgs e)
{
//方法
SystemDataDataTable table = SystemDataSqlClientSqlClientFactoryInstanceCreateDataSourceEnumerator()GetDataSources();
GridViewDataSource = table;
GridViewDataBind();
//得到本机的
foreach (SystemDataDataRow row in tableRows)
{
if (row[]ToString()ToUpper()Equals(SystemNetDnsGetHostName()ToUpper()))
{
ResponseWrite("<li>" + row[]);
}
}
//方法
//需要引用MicrosoftSqlServerSmodll
GridViewDataSource = MicrosoftSqlServerManagementSmoSmoApplicationEnumAvailableSqlServers(true);
GridViewDataBind();
}
</script>
<html xmlns="
<head id="Head" runat="server">
<title></title>
</head>
<body>
<form id="form" runat="server">
<asp:GridView ID="GridView" runat="server">
</asp:GridView>
<asp:GridView ID="GridView" runat="server">
</asp:GridView>
</form>
</body>
</html>