ADO Net Database ASP.Net Tutorial

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" 
    Inherits="Default"%>



    Agnostic


        
    

    
    
        
            
            
            
            
            
            
            
            
            
            
            
            
            
            
Provider                text="System.Data.SqlClient">
Connection String                text="SERVER=(local);DATABASE=northwind;Trusted_Connection=yes;">
Command Text                text="SELECT TOP 15 customerid, companyname FROM customers">

            
            
            
                
            
        
    



File: Default.aspx.cs
using System;
using System.Data;
using System.Data.Common;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default : System.Web.UI.Page
{
    protected void RunButton_Click(object sender, EventArgs e)
    {
        string provider = ProviderNameBox.Text;
        string connString = ConnectionStringBox.Text;
        string commandText = CommandTextBox.Text;
        DbProviderFactory fact = DbProviderFactories.GetFactory(provider);
        DbConnection conn = fact.CreateConnection();
        conn.ConnectionString = connString;
        DbDataAdapter adapter = fact.CreateDataAdapter();
        adapter.SelectCommand = conn.CreateCommand();
        adapter.SelectCommand.CommandText = commandText;
        DataTable table = new DataTable();
        adapter.Fill(table);
        Results.DataSource = table;
        Results.DataBind();
    }
}