我正在尝试访问下拉列表中的选定值并在select语句中传递该值,因此我只能提取过滤后的数据,但是我收到错误并且由于此问题而未生成图表。这是错误:“错误:'pieYScale'为null或不是对象” 我怀疑我在下拉列表中引用所选值的方式是错误的。
public string CreateChart()
{
string DDList = DropDownList1.SelectedValue;
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString);
string sqlStatement = "select Status as GroupCategory, Count(Status) as TotalCount from [MasterProject] where Closing_Date >= '" + txtStartClosingDate.Text + "' and Closing_Date <= '" + txtEndClosingDate.Text + "' and GroupProject = '" + DDList + "' and Status is not null group by Status Order by TotalCount Desc";
SqlCommand cmd = new SqlCommand(sqlStatement, con);
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
string strXML;
strXML = "<graph decimalPrecision='0' name='MyXScaleAnim' type='ANIMATION' duration='1' start='0' param='_xscale' showNames='1' labelDisplay='Rotate' useEllipsesWhenOverflow='1' pieSliceDepth='30' formatNumberScale='0'>";
while (reader.Read())
{
strXML += "<set name='" + reader["GroupCategory"].ToString() + "' value='" + reader["TotalCount"].ToString() + "' />";
}
strXML += "</graph>";
return FusionCharts.RenderChart("../FusionCharts/Column3D.swf", "ChartID", strXML, "FactorySum", "500", "350", false, false);
}
答案 0 :(得分:0)
除了上面的代码完全对SQL注入攻击等开放之外,实际错误本身来自FusionCharts组件并且似乎是一个错误,需要更新来修复它。见here
答案 1 :(得分:0)
我已经使用它修复了它:
string DDList = DropDownList1.SelectedItem.Value;