数据视图过滤问题
有人可以帮忙编写以下代码吗?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
数据视图过滤器不是这样工作的。它的语法类似于 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.