using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; using System.Web.Services; using System.Web.Script.Services;
public partial class jQueryGoogleChart : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { GetChartData(); } [WebMethod] [ScriptMethod (ResponseFormat = ResponseFormat.Json)] public static List GetChartData() { DataTable dt = new DataTable(); using (SqlConnection con = new SqlConnection(@"Data Source=(local);Initial Catalog=Venda;Integrated Security=True")) { con.Open(); SqlCommand cmd = new SqlCommand("SELECT ProductName as Name, COUNT(Pu) AS Total FROM Produto GROUP BY ProductName", con); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(dt); con.Close(); } List dataList = new List(); foreach (DataRow dtrow in dt.Rows) { Produto details = new Produto(); details.ProductName = dtrow[0].ToString(); details.Pu = Convert.ToInt32(dtrow[1]); dataList.Add(details); } return dataList; }
public class Produto
{
public string ProductName { get; set; }
public int Pu { get; set; }
}
}