Tuesday, August 14, 2012

Show sql server instances with the network (ASP.NET)

The key is the SqlDataSourceEnumerator to display all instances. You can use gridview or ajax controls for display purposes.
Code:
      protected void Page_Load(object sender, EventArgs e)  
      {  
        // Retrieve the enumerator instance and then the data.  
        SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance;  
        System.DataDataTable table = instance.GetDataSources();  
        // Display the contents of the table.  
        DisplayData(table);  
      }  

      private void DisplayData(System.DataDataTable table)  
      {  
        foreach (System.DataDataRow row in table.Rows)  
        {  
          foreach (System.DataDataColumn col in table.Columns)  
          {  
            Response.Write(String.Format("{0} = {1}<br>",  
              col.ColumnName, row[col]));  
          }  
        }  
      } 

2 comments:

  1. I am learning Asp.Net Development. Can you provide me more information regarding "sql server" and "SqlDataSource".

    ReplyDelete
    Replies
    1. Hi anna,

      there are tons of resources in the internet for sql server and sql datasource.

      You could start at Microsoft's asp.net website. Aside from that, there are customized tutorials for your needs.

      Cheers! ;)

      Delete