Exemple #1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Request.QueryString["name"] != null)
     {
         this.name = Request.QueryString["name"].ToString();
         conn      = new DBConnection();
         ds        = conn.getTable("Report", "SELECT * FROM Report WHERE City='" + this.name + "'");
         if (ds != null && ds.Tables["Report"] != null)
         {
             ListViewCity.DataSource = ds.Tables["report"];
             ListViewCity.DataBind();
         }
     }
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            var liste = new List <Cities>();

            using (var con = new SqlConnection(
                       ConfigurationManager.ConnectionStrings["NorthwindConnectionString1"].ConnectionString))
            {
                var sql = "select city, count(*) as anzahl from customers group by city order by city";
                //datatable ist bäh -generische Liste
                var cmd = new SqlCommand(sql, con);
                con.Open();
                var rd = cmd.ExecuteReader();
                while (rd.Read())
                {
                    liste.Add(new Cities {
                        Anzahl = int.Parse(rd["Anzahl"].ToString()),
                        City   = rd["City"].ToString()
                    });
                }
            }
            ListViewCity.DataSource = liste;
            ListViewCity.DataBind();
        }