<@ Page Language="C#" AutoEventWireup="true" CodeBehind="PieChart.aspx.cs" Inherits="PieChart" >
<%@ register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager>
<div style="width: 337px; height: 379px;">
<asp:PieChart>
</asp:PieChart>
</div>
</form>
</body>
</html>
C# Code:
protected void Page_Load(object sender, EventArgs e)
//for sqlserver authentication connection string-(server,databasename,Windows authentication)
{
string connstr = "server=.\\SQLEXPRESS;database=Employee;integreted security=ture";
//class System.Data.SqlClient.SqlConnection -Represent an open connection to a SQL Server database
//initializes instance of class SqlConnection
SqlConnection conn = new SqlConnection(connstr);
//select query for fetch the data from database table population
string query = "select * from population";
//class System.Data.SqlClient. SqlDataAdapter-
//Represent a set of data commands and a databse connection that are used to fill
// the System.Data.Dataset and update a sql server database
//Initializes instance of class SqlDataAdapter
SqlDataAdapter da = new SqlDataAdapter(query, conn);
//Initializes instance of System.Data.Dataset class
DataSet ds = new DataSet();
//adds or refreshes rows in the System.Data.Dataset by Fill() Method
da.Fill(ds);
foreach (DataRow row in ds.Tables[0].Rows)
{
PieChart1.PieChartValues.Add(new AjaxControlToolkit.PieChartValue
{
Category = row["country"].ToString(),
Data = Convert.ToDecimal(row["population"])
});
}
}
No comments:
Post a Comment