我正在尝试使用like参数使用控制参数在数据库中的日期字段中获取年份。我需要这个工作在aspx而不是aspx.cs页面。以下是我的代码:
<asp:SqlDataSource ID="getStudentResultsYearOne" runat="server"
ConnectionString="<%$ ConnectionStrings:UniString %>"
SelectCommand="SELECT DISTINCT modules.module_name, student_module_grade.grade, module_desc.cat_points,student_module_grade.result_code, student_module_grade.module_grade_id FROM modules INNER JOIN module_on_pathway ON modules.id = module_on_pathway.module_id INNER JOIN module_desc ON modules.id = module_desc.module_id INNER JOIN year_in_pathway ON module_on_pathway.year_in_pathway_id = year_in_pathway.id INNER JOIN pathway_years ON year_in_pathway.pathway_year_id = pathway_years.id INNER JOIN class ON pathway_years.id = class.pathway_year_id INNER JOIN classlist ON class.class_id = classlist.class_id INNER JOIN student_module_grade ON module_on_pathway.id = student_module_grade.module_on_pathway_id INNER JOIN users ON classlist.user_id = users.id INNER JOIN chosen_modules_list ON classlist.classlist_id = chosen_modules_list.classlist_id WHERE (chosen_modules_list.module_on_pathway_id = module_on_pathway.id OR module_on_pathway.mandatory_module = 1) AND module_on_pathway.pathway_year_id = @pathway_years_id AND (year_in_pathway.year_end LIKE '%'+ @maxYear +'%')">
<SelectParameters>
<asp:SessionParameter Name="student_id" SessionField="UserLoggedOn" Type="Int32" />
<asp:ControlParameter Name="pathway_years_id" ControlID="pathwayYearsId" PropertyName="Text" Type="Int32" />
<asp:ControlParameter Name="maxYear" ControlID="lastYear" PropertyName="Text" Type="String" />
</SelectParameters>
(这是用于将当前年份与我在数据库中的日期进行比较的标签)
<asp:Label ID="lastYear" runat="server" Visible="false"></asp:Label>
(这是在.cs文件中获取当前年份并填充上面提到的标签)
protected void Page_Load(object sender, EventArgs e)
{
DateTime Today = DateTime.Today;
Int32 currentYear = Today.Year;
lastYear.Text = Convert.ToString(currentYear);
}
感谢您提供的任何帮助。 :)