Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1033609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:15:28+00:00 2026-05-16T14:15:28+00:00

hello friends following is my query where displaylist is object if stringBuilder which have

  • 0

hello friends following is my query where displaylist is object if stringBuilder which have zero length sometimes but in that case it gives error incorrect syntax near FROM so how can i avoid this problem do i need to write a different query in if else form to avoid this or please suggest me a best solution to make and also from efficiency and performance point of view

string cmd = @"SELECT [tbl_course].course_name as Course_Name , [tbl_branch].branch_name as Branch_Name,"+displayList+@" FROM [tbl_students], [tbl_course], [tbl_branch] 
                        WHERE [tbl_students].course_id= @courseId 
                        AND   [tbl_students].branch_id IN(" + branchId + @") 
                        AND  (@firstYrPercent is null OR[tbl_students].first_year_percent>=@firstYrPercent)
                        AND  (@secondYrpercent is null OR[tbl_students].second_year_percent>=@secondYrPercent)
                        AND  (@thirdYrPercent is null OR[tbl_students].third_year_percent>=@thirdYrPercent)
                        AND  (@finalYearpercent is null OR[tbl_students].final_year_percent>=@finalYearpercent)
                        AND  (@currentDegeePercentage is null OR[tbl_students].current_degree_percent>=@currentDegeePercentage)
                        AND  (@passoutYear is null OR[tbl_students].passing_year>=@passoutYear) 
                        AND  (@currentBacklog is null OR[tbl_students].current_backlog<=@currentBacklog)
                        AND   [tbl_students].gender=@sex 
                        AND  (@eGap is null OR [tbl_students].gapin_education<=@eGap)
                        AND  (@highSchoolPercentge is null OR[tbl_students].highschool_percentage>=@highSchoolPercentge)
                        AND  (@higherSchoolPercentage is null OR[tbl_students].ssc_percentage>=@higherSchoolPercentage)
                        AND  (@grauationPercentage is null OR[tbl_students].graduation_percentage>=@grauationPercentage)
                        AND  (@diplomaPercentage is null OR[tbl_students].diploma_percentage>=@diplomaPercentage)
                        AND  (@noOfAtkt is null OR[tbl_students].number_of_ATKT<=@noOfAtkt)
                        AND  (@validDate is null OR[tbl_students].DOB<=@validDate)
                        AND  [tbl_students].branch_i

d=[tbl_branch].branch_id AND [tbl_students].course_id=[tbl_course].course_id";
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T14:15:29+00:00Added an answer on May 16, 2026 at 2:15 pm

    The problem is the comma right before you insert the value of displayList. If displayList is empty, then your SQL statement looks like this:

    ...[tbl_branch].branch_name as Branch_Name, FROM [tbl_students]...
    

    So either include the comma in dispalyList (displayList = ", [tbl_branch].branch_foo") or use a conditional statement, when inserting it into the SQL:

    string cmd = @"SELECT [tbl_course].course_name as Course_Name , [tbl_branch].branch_name as Branch_Name" + String.IsNullOrEmpty(displayList) ? "" : ", " + displayList + @" FROM [tbl_students]...";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I have the following error by git-fsck, which cannot be cleaned by git-gc
hello friends i am following 3 layer architecture for my project i mean presentation
Hello friends I am getting the following error while making the foreign key 'tbl_course'
Hello friends i have a form view i have handele all needed events successfully
Hallo,friends we have the following problem syms t u0 u1 u0=sin(t); R1= diff(u0,'t',2)+u0-u0^3; u1=dsolve('D2u1+u1=R1','t')
Hallo friends, I want to figure out the following problem: Suppose,we have expression like,
Hello again ladies and gents! OK, following on from my other question on ASP.NET
Hello can anybody solve this please I'm creating the object in the action class
Hello I am compiling a program with make but I get the error of
Hello I am working with a simulator that uses rcS scripts to boot, this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.