0

我正在尝试显示 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 not found 的错误列,我无法理解为什么会出现此错误。

4

1 回答 1

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

于 2013-07-10T07:47:16.953 回答