熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

asp.net得到本機數據庫實例的兩種方法代碼

2022-06-13   來源: .NET編程 
這篇文章介紹了aspnet得到本機數據庫實例的兩種方法代碼有需要的朋友可以參考一下   復制代碼 代碼如下:

  
<%@ 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>


From:http://tw.wingwit.com/Article/program/net/201311/14010.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.