【发布时间】:2010-08-18 15:22:30
【问题描述】:
你好朋友,我有以下查询,这违背了目的。
一天前,我要求对电路进行排序的建议,因为我得到了使用的建议(@firstYrPercent is null OR first_year_percent>=@firstYrPercent) 像这样拒绝空参数,但是今天当我运行实际查询时,我认为上面提到的想法是没有用的。
我正在为所有那些为 null 的参数获取 sql 异常,并且这些错误的要求值是这个 Sql 异常被捕获:
“参数化查询'(@courseId int,@passoutYear int,@currentBacklog int,@sex int,@eG' 需要参数@currentDegeePercentage,但未提供。"
这是查询,请给我建议一个替代方案:
string cmd = @"SELECT * FROM [tbl_students] WHERE course_id=@courseId
AND branch_id IN(" + branchId + @")
AND (@firstYrPercent is null OR first_year_percent>=@firstYrPercent)
AND (@secondYrpercent is null OR second_year_percent>=@secondYrPercent)
AND (@thirdYrPercent is null OR third_year_percent>=@thirdYrPercent)
AND (@finalYearpercent is null OR final_year_percent>=@finalYearpercent)
AND (@currentDegeePercentage is null OR current_degree_percent>=@currentDegeePercentage)
AND (@passoutYear is null OR passing_year>=@passoutYear)
AND (@currentBacklog is null OR current_backlog<=@currentBacklog)
AND gender=@sex
AND (@eGap is null OR gapin_education<=@eGap)
AND (@highSchoolPercentge is null OR highschool_percentage>=@highSchoolPercentge)
AND (@higherSchoolPercentage is null OR ssc_percentage>=@higherSchoolPercentage)
AND (@grauationPercentage is null OR graduation_percentage>=@grauationPercentage)
AND (@diplomaPercentage is null OR diploma_percentage>=@diplomaPercentage)
AND (@noOfAtkt is null OR number_of_ATKT<=@noOfAtkt)
AND (@date is null OR DOB>=@date)";
【问题讨论】: