asp.net图表。未找到列错误

时间:2013-07-10 07:41:46

标签: asp.net sql-server charts

我正在尝试显示asp.net图表。 我写了以下代码

public SqlDataAdapter da;
DataSet ds1;
public DataSet SelectDayWiseEnquiriesForCChart()
{
    int orgid;
    orgid = ((int)Session["orgid"]);
    DbConnect objdbc = new DbConnect();
    SqlConnection con = objdbc.openConnection();
    da = new SqlDataAdapter("SELECT EnquiryOwner,Count(uid) from EnquiryMaster WHERE orgid='" + orgid + "' and ( DAY(date) = DAY(GETDATE()) AND MONTH(date) = MONTH(GETDATE()) AND YEAR(date) = YEAR(GETDATE()) ) group by EnquiryOwner", con);
    ds1 = new DataSet();
    da.Fill(ds1);
    return ds1;
}

protected void FillChartControl()
{
    Chart1.DataSource = SelectDayWiseEnquiriesForCChart();

    Chart1.DataBind();
}
       <asp:Chart ID="Chart1" runat="server">
            <series>
                <asp:Series Name="Series1" XValueMember="EnquiryOwner" YValueMembers="uid">
                </asp:Series>
            </series>
            <chartareas>
                <asp:ChartArea Name="ChartArea1">
                </asp:ChartArea>
            </chartareas>
        </asp:Chart>

我收到一个错误列,找不到名称uid 我无法理解为什么会出现此错误。

1 个答案:

答案 0 :(得分:0)

在查询中使用count()表达式的别名。

da = new SqlDataAdapter("SELECT EnquiryOwner,Count(uid) as uid from EnquiryMaster WHERE ....

然后您可以在YValueMembers="uid"

中使用该名称

取自MSDN:

  

...您可以使用序号位置0作为结果名称来访问返回结果。要按列名访问返回结果,查询必须包含AS子句以提供列名。

http://msdn.microsoft.com/en-us/library/cc280492%28v=SQL.100%29.aspx