2010-10-22 57 views
0

有人可以用下面的代码来帮忙!Dataview Filteration问题

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(); 
} 

当尝试了在运行时会引发下面的错误:

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

请帮忙!!

回答

0

Dataview过滤器不会这样工作。它的语法与sql类似,但这并不意味着您可以在过滤器中调用sql函数。