ADO Database ASP.Net

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web.Configuration" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Common" %>

    void Page_Load(object source, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            DataTable table = DbProviderFactories.GetFactoryClasses();
            ddlProvider.DataSource = table;
            ddlProvider.DataTextField = "Name";
            ddlProvider.DataValueField = "InvariantName";
            ddlProvider.DataBind();
        }
    }
    void btnExecute_Click(object sender, EventArgs e)
    {                
        string sql = "Select * from " + txtTableName.Text;
        ExecuteQuery(ddlProvider.SelectedItem.Value, sql);        
    }
    void ExecuteQuery(string providerName, string sql)
    {        
        DbProviderFactory factory = DbProviderFactories.GetFactory(providerName);
        string connectionString = CreateConnectionString(factory.CreateConnectionStringBuilder());
        using (DbConnection conn = factory.CreateConnection())
        {            
            conn.ConnectionString = connectionString;
            using (DbDataAdapter adapter = factory.CreateDataAdapter())
            {
                adapter.SelectCommand = conn.CreateCommand();
                adapter.SelectCommand.CommandText = sql;
                DataTable table = new DataTable("Table");
                adapter.Fill(table);
                gridResults.DataSource = table;
                gridResults.DataBind();
            }
        }
    }
    private string CreateConnectionString(DbConnectionStringBuilder builder)
    {
        builder.Add("Integrated Security", true);
        builder.Add("Initial Catalog", txtDatabaseName.Text);
        builder.Add("Data Source", txtServerName.Text);
        return builder.ConnectionString;
    }



    Executing Dynamic Queries using Provider Independant Code


    
    

        
            
                
                
            
            
                
                
            
            
                
                
            
            
                
                
            
            
                
                                
                
            

        
Select Provider:
Server Name:
Database Name: 
Table Name: 

                              HeaderStyle-ForeColor="Brown" 
                      RowStyle-BackColor="Snow" 
                      runat="Server" 
                      ID="gridResults">