2010-10-22 24 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函數。