01.
public
partial
class
WebForm1 : System.Web.UI.Page
02.
{
03.
OleDbConnection conObj =
new
OleDbConnection();
04.
OleDbDataAdapter da;
05.
DataSet ds =
new
DataSet();
06.
protected
void
Page_Load(
object
sender, EventArgs e)
07.
{
08.
09.
}
10.
11.
protected
void
DropDownList1_SelectedIndexChanged(
object
sender, EventArgs e)
12.
{
13.
Chart1.Visible = DropDownList1.SelectedValue !=
""
;
14.
string
query =
string
.Format(
"select employeeNormal, from list orders group by shipcity"
, DropDownList1.SelectedValue);
15.
DataTable dt = GetData(query);
16.
string
[] x =
new
string
[dt.Rows.Count];
17.
int
[] y =
new
int
[dt.Rows.Count];
18.
for
(
int
i = 0; i < dt.Rows.Count; i++)
19.
{
20.
x[i] = dt.Rows[i][0].ToString();
21.
y[i] = Convert.ToInt32(dt.Rows[i][1]);
22.
}
23.
Chart1.Series[0].Points.DataBindXY(x, y);
24.
Chart1.Series[0].ChartType = SeriesChartType.Pie;
25.
Chart1.ChartAreas[
"ChartArea1"
].Area3DStyle.Enable3D =
true
;
26.
Chart1.Legends[0].Enabled =
true
;
27.
}
28.
29.
protected
void
DropDownList2_SelectedIndexChanged(
object
sender, EventArgs e)
30.
{
31.
32.
}
33.
34.
protected
void
BuildChart()
35.
{
36.
var ddl3Value = DropDownList1.SelectedValue;
37.
var ddl2Value = DropDownList2.SelectedValue;
38.
39.
if
(ddl3Value !=
null
&& ddl2Value !=
null
)
40.
{
41.
string
strCon =
""
;
42.
strCon =
""
;
43.
string
strPath = System.IO.Directory.GetCurrentDirectory();
44.
45.
strCon =
"Provider=Microsoft.ACE.OLEDB.12.0;"
46.
+
"Data Source="
+ strPath +
"\\Database1.accdb;"
47.
+
"Persist Security Info=False;"
;
48.
49.
if
(conObj.State == ConnectionState.Open)
50.
{
51.
conObj.Close();
52.
}
53.
else
54.
{
55.
conObj.ConnectionString = strCon;
56.
conObj.Open();
57.
}
58.
59.
string
strSQL =
"SELECT employee.* FROM list;"
;
60.
61.
62.
da =
new
OleDbDataAdapter(strSQL, conObj);
63.
64.
65.
ds.Tables.Clear();
66.
da.Fill(ds,
"MyQuery"
);
67.
68.
}
69.
}
70.
71.
protected
void
DropDownList2_SelectedIndexChanged1(
object
sender, EventArgs e)
72.
{
73.
74.
}
75.
76.
77.
private
static
DataTable GetData(
string
query)
78.
{
79.
DataTable dt =
new
DataTable();
80.
SqlCommand cmd =
new
SqlCommand(query);
81.
String constr = ConfigurationManager.ConnectionStrings[
"ConString"
].ConnectionString;
82.
SqlConnection con =
new
SqlConnection(constr);
83.
SqlDataAdapter sda =
new
SqlDataAdapter();
84.
cmd.CommandType = CommandType.Text;
85.
cmd.Connection = con;
86.
sda.SelectCommand = cmd;
87.
sda.Fill(dt);
88.
return
dt;
89.
}
90.
}