2010-08-17 181 views
-2

什么是上述错误,请更正SQL异常(附近有语法错误)')

string cmd = @"SELECT * FROM [tbl_students] WHERE [email protected] 
       AND branch_id IN(" + branchId + @") 
       AND (@firstYrPercent is null OR first_year_percent>[email protected] 
       AND (@secondYrpercent is null OR second_year_percent>[email protected]) 
       AND (@thirdYrPercent is null OR third_year_percent>[email protected]) 
       AND (@finalYearpercent is null OR final_year_percent>[email protected]) 
       AND (@currentDegeePercentage is null OR current_degree_percent>[email protected]) 
       AND (@passoutYear is null OR passing_year>[email protected]) 
       AND (@currentBacklog is null OR current_backlog<[email protected]) 
       AND [email protected] 
       AND (@eGap is null OR gapin_education<[email protected]) 
       AND (@highSchoolPercentge is null OR highschool_percentage>[email protected]) 
       AND (@higherSchoolPercentage is null OR ssc_percentage>[email protected]) 
       AND (@grauationPercentage is null OR graduation_percentage>[email protected]) 
       AND (@diplomaPercentage is null OR diploma_percentage>[email protected]) 
       AND (@noOfAtkt is null OR number_of_ATKT<[email protected]) 
       AND (@date is null OR DOB>[email protected])"; 
+2

可能的重复[请纠正我与SQL查询](http://stackoverflow.com/questions/3499381/pl易于纠正与我的SQL查询)**和** http://stackoverflow.com/questions/3499584 – gbn 2010-08-17 07:05:21

回答

3

你必须要在第3行的末尾缺少一个右括号:

AND (@firstYrPercent is null OR first_year_percent>[email protected] 
+0

是的,你是正确的,但现在它给予异常我没有得到异常我发送所有的参数的适当,尽管没有喘息 参数化查询'(@ courseId int,@ passoutYear int,@ currentBacklog int,@ sex int,@ eG'期望参数@eGap,它没有提供。 – NoviceToDotNet 2010-08-17 07:01:29

+0

我已经用调试器测试了它,但是利用了 每一件事情似乎都很好,但是它产生了同样的错误请修复它的原因是什么 – NoviceToDotNet 2010-08-17 07:09:24

+0

我认为它是检查或空值参数以及如果没有palue是截断提供的是真的吗? 如果是这样,请让我知道我该如何解决这个问题? – NoviceToDotNet 2010-08-17 07:17:23

1

下面的行没有右括号

AND (@firstYrPercent is null OR first_year_percent>[email protected] 
+0

是你正确的,但现在它给予异常我没有得到异常我发送所有参数的适当,尽管没有喘息参数化查询'(@courseId int,@ passoutYear int,@ currentBacklog int,@ sex int,@ eG'期望参数@eGap,未提供。 – NoviceToDotNet 2010-08-17 07:12:51

+0

请提供完整的代码,说明如何执行提供的查询和确切的异常消息 – 2010-08-17 07:34:22