1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| protected void Page_Load(object sender, EventArgs e)
{
//String str = "Data Source=pc-01;Initial Catalog=GEL;Integrated Security=True; Asynchronous Processing = true";
//SqlConnection conn = new SqlConnection(str);
//conn.Open();
if (!IsPostBack)
{
// Declare the query string.
String queryString ="Select nom, prenom From personne";
// Run the query and bind the resulting DataSet
// to the GridView control.
DataSet ds = GetData(queryString);
if (ds.Tables.Count > 0)
{
GridView1.DataSource = ds;
GridView1.DataBind();
}
else
{
Message.Text = "Unable to connect to the database.";
}
}
}
DataSet GetData(String queryString)
{
String str = "Data Source=localhost; Initial Catalog=GEL;Integrated Security=True; Asynchronous Processing = true";
SqlConnection conn = new SqlConnection(str);
conn.Open();
DataSet ds = new DataSet();
try
{
SqlDataAdapter adapter = new SqlDataAdapter(queryString, conn);
adapter.FillSchema(ds,SchemaType.Mapped,"personne");
//adapter.Fill(ds,"personne");
}
catch(Exception ex)
{
// The connection failed. Display an error message.
Message.Text = "Unable to connect to the BDD.";
}
return ds;
}
} |