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

  • SEARCH
  • Home
  • 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 8010949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:53:19+00:00 2026-06-04T18:53:19+00:00

In my scenario I have to build a dynamic query based on what the

  • 0

In my scenario I have to build a dynamic query based on what the user selects on the screen.

The user can select a columnname, then an operator and then type a value.

I already did it for the equal, but how it would be the syntax for the LIKE and NOT LIKE?
so

1st. I add the Column names to my list

var columns = new Dictionary<string, string>
              {
                {"CurrentStatus", "Current Status"},
                {"RequestNumber", "Request Number"},
                {"RequestDate", "Request Date"},
                {"IsOnHold", "Is On Hold"},
                {"BrandReturnedVehicle", "Brand Returned Vehicle"},
                {"TypeReturnedVehicle", "Type Returned Vehicle"},
                {"ChassisReturnedVehicle", "Chassis Returned Vehicle"},
                {"DestructionCertificateNumberReturnedVehicle", 
                              "Destruction Certificate Number Returned Vehicle"},
                {"AmmountWithVAT", "Ammount WithVAT "},
                {"AmmountWithoutVat", "Ammount Without Vat"},
                {"Percentage", "Percentage"},
                {"VehicleDestructionDate", "Vehicle Destruction Date"},
                {"Comments", "Comments"},
                {"Discriminator", "Request Type"},
              };

                DdlColumn1.DataSource = columns;  
                DdlColumn1.DataTextField = "Value";
                DdlColumn1.DataValueField = "Key";              
                DdlColumn1.DataBind();

2nd. Depending on the selected column name, I add the operators to the dropdownlist.

protected void DdlColumn1SelectedIndexChanged(object sender, EventArgs e)
        {
            LoadOperatorsDependingOnColumn(sender as DropDownList, DdlColumn1.SelectedValue);
        }


    private void LoadOperatorsDependingOnColumn(DropDownList ddlOperators, string columnname)
                {
                    var operators = new Dictionary<string, string>();
                    operators.Clear();
                    switch (columnname)
                    {
                        case "CurrentStatus":
                            AddTextOperatorsToList(operators);
                            ddlOperators.DataSource = operators;
                            ddlOperators.DataTextField = "Value";
                            ddlOperators.DataValueField = "Key";
                            ddlOperators.DataBind();
                            break;
                        case "AmmountWithVat":
                            AddNumberOperatorsToList(operators);
                            break;
                    }
                }


private static void AddTextOperatorsToList(Dictionary<string, string> operators)
            {
                operators.Add("==", "Equals");
                operators.Add("<>", "Not Equals");
                operators.Add("LIKE", "Contains");
                operators.Add("NOT LIKE", "Does not Contain");
            }

            private static void AddNumberOperatorsToList(Dictionary<string, string> operators)
            {
                operators.Add("=", "Equals");
                operators.Add("<>", "Not Equals");
                operators.Add(">", "Greater than");
                operators.Add(">=", "Greater or equal than");
                operators.Add("<", "Less than");
                operators.Add("<=", "Less or equal than");
            }

private string ColumnType(string columnName)
            {
                switch (columnName)
                {
                    case "CurrentStatus":
                        return "Text";
                        break;
                    case "RequestNumber":
                        return "Text";
                        break;
                }
            }

            private string BuildQuery()
            {
                var sb = new StringBuilder();
                        //var list = RequestBaseBL.GetRequestByCustomQuery("RequestNumber == \"12\"");

                if (ColumnType(DdlColumn1.SelectedValue) == "Text" && DdlOperator1.SelectedItem.Text=="==")
                {
                    sb.Append(DdlColumn1.SelectedValue);
                    sb.Append(DdlOperator1.SelectedValue);
                    sb.Append("\"" +  TxtValue1.Text + "\"");
                }
  1. What I dont know is how to concatenate/append the strings to make the Not Equal, Contains and Does not contain to work with the dynamic linq libray
  • 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-06-04T18:53:20+00:00Added an answer on June 4, 2026 at 6:53 pm

    It would appear that the dynamic linq stuff doesn’t support ‘LIKE’ – but I guess that’s why you’re asking the question. The best I could come up with is to replace LIKE with something like (x >= y0 AND x < y1).
    So:

    if (ColumnType(DdlColumn1.SelectedValue) == "Text" && DdlOperator1.SelectedItem.Text=="LIKE")
    {
        string s = TxtValue1.Text;
        Char c = s[s.Length - 1];
        string s1 = s.Substring(0, s.Length - 1) + ((Char)(c + 1));
        string clause = string.Format("{0} >= \"{1}\" and {0} < \"{2}\"", DdlColumn1.SelectedValue, s, s1);
        sb.Append(clause);
    }
    

    ie Add 1 to the value of the last character of the search string and use that as an upper bound for the search.
    If you know you’re only dealing with simple Latin charactersets you could make it slightly simpler and use:

    string clause = string.Format("{0} >= \"{1}\" and {0} <= \"{1}z\"", DdlColumn1.SelectedValue, TxtValue1.Text);
    

    But it might be worth taking a look at the predicate builder here to get more type safety.

    EDIT

    Well I never! Forget all that.

    It seems you can use “myField.Contains(myCriteria)” and “myField.StartsWith(myCriteria)” for CONTAINS and LIKE

    sb.Append(string.Format("{0}.Contains(\"{1}\")", DdlColumn1.SelectedValue, TxtValue1.Text);
    

    and

    sb.Append(string.Format("{0}.StartsWith(\"{1}\")", DdlColumn1.SelectedValue, TxtValue1.Text);
    

    and, for NOT LIKE:

    sb.Append(string.Format("!{0}.StartsWith(\"{1}\")", DdlColumn1.SelectedValue, TxtValue1.Text);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Scenario I have created a page where the client can build their own page,
Scenario I have a C# application compiled as a DLL. I have a build
How can i compress individual css files using YUI build task (or otherwise). Scenario:
I have to build a number of small independent applications, that can be copied
I'm having a scenario where i have to build multilingual index. specially for two
I am wondering how to build the follwoing scenario: - I have one app
I have Problem with chat application . my scenario: I need to build chat
I have scenario like this Given /^initial data$/ do |table| @schedule_05 = Factory.build :schedule_05
I'm trying to build a query with hibernate criteria for the following scenario: Two
Beginner level question Scenario: Have simple string cocantation tool, that I might expand later

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.