数据视图过滤问题

发布于 2024-09-28 18:10:58 字数 822 浏览 0 评论 0原文

有人可以帮忙编写以下代码吗?

if (DiaryOccasions != null && DiaryOccasions.Rows.Count > 0)
{
    DataTable dtFilteredOccasions = new DataTable();

    if (ddlMonths.SelectedItem.Value != string.Empty)
    {
        string[] selMonthYear = ddlMonths.SelectedItem.Value.Split('/');

        if(selMonthYear.Length > 0)
        {
            dtFilteredOccasions = new DataView(DiaryOccasions,
                string.Format("MONTH(OccasionDate) = {0} AND YEAR(OccasionDate) = {1}",
                    selMonthYear[0].ToString(), selMonthYear[1].ToString()), 
                string.Empty, DataViewRowState.CurrentRows).ToTable();
        }
    }

    rptrDates.DataSource = dtFilteredOccasions;
    rptrDates.DataBind();
}

当尝试时,它在运行时抛出以下错误:

表达式包含未定义的函数调用 MONTH()。

请帮忙!!

Can some one help with with the following code please!!

if (DiaryOccasions != null && DiaryOccasions.Rows.Count > 0)
{
    DataTable dtFilteredOccasions = new DataTable();

    if (ddlMonths.SelectedItem.Value != string.Empty)
    {
        string[] selMonthYear = ddlMonths.SelectedItem.Value.Split('/');

        if(selMonthYear.Length > 0)
        {
            dtFilteredOccasions = new DataView(DiaryOccasions,
                string.Format("MONTH(OccasionDate) = {0} AND YEAR(OccasionDate) = {1}",
                    selMonthYear[0].ToString(), selMonthYear[1].ToString()), 
                string.Empty, DataViewRowState.CurrentRows).ToTable();
        }
    }

    rptrDates.DataSource = dtFilteredOccasions;
    rptrDates.DataBind();
}

when tried it throws the following error at runtime:

The expression contains undefined function call MONTH().

Please help !!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天冷不及心凉 2024-10-05 18:10:59

数据视图过滤器不是这样工作的。它的语法类似于 sql,但这并不意味着您可以在过滤器中调用 sql 函数。

Dataview Filters do not work that way. It's syntax is similar to sql, but that doesn't mean you are allowed to call sql functions in your filter.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文