using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Data.Common;

public partial class test_fabrique : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
		// récupérer le nom de la base "active"
		string cle = ConfigurationManager.AppSettings["base"].ToString();
		ConnectionStringSettings cs = ConfigurationManager.ConnectionStrings[cle];

		// obtenir une fabrique pour SQL Server
		//DbProviderFactory fac = DbProviderFactories.GetFactory("System.Data.SqlClient");
		DbProviderFactory fac = DbProviderFactories.GetFactory(cs.ProviderName);

		// créer une connexion pour SQL Server à partir de la fabrique
		DbConnection cx = fac.CreateConnection();
		//cx.ConnectionString = ConfigurationManager.ConnectionStrings["bancaConnectionString"].ConnectionString;
		cx.ConnectionString = cs.ConnectionString;

		// créer une commande
		DbCommand sql = fac.CreateCommand();
		sql.Connection = cx;
		sql.CommandText = "select * from compte where solde > @solde";
		DbParameter ps = fac.CreateParameter();
		ps.ParameterName = "@solde";
		ps.Value = "30";
		sql.Parameters.Add(ps);

		// exécuter la commande
		cx.Open();
		GridView1.DataSource = sql.ExecuteReader(CommandBehavior.CloseConnection);
		GridView1.DataBind();
    }
}
