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 64097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:44:11+00:00 2026-05-10T18:44:11+00:00

I have a database table named call with columns call_time, location, emergency_type and there

  • 0

I have a database table named call with columns call_time, location, emergency_type and there are three types of emergency: paramedics, police and firefighters. In the windows form I created CheckBoxes ‘paramedics’, ‘police’, ‘firefighters’ and I want to retrieve all table columns which meet user’s selection.

I created a function:

public static DataTable GetHistory(DateTime from, DateTime to, bool paramedics, bool police, bool firefighters)     {         string select =             'SELECT call_time, location, emergency_type where call_time between @from AND @to AND';         if(paramedics)         {             select += ' emergency_type = 'paramedics' ';         }         if(paramedics && police)         {            select +=' emergency_type = 'paramedics' OR emergency_type = 'police';         }         ...      } 

This code however seems very dirty because if there were 30 kinds of emergency there would be 30! combinations and I would get old before writing all if statements.

I would appreciate if you shared your practice for retrieving data that meet the selected search conditions if there are many options you can chosse.

Thanks!

  • 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. 2026-05-10T18:44:12+00:00Added an answer on May 10, 2026 at 6:44 pm

    Well if you have to use emergency_type as a string then instead of passing in bools you could send in a List containing the text representation of the emergency type. For example to adjust the above code you could change the method signature to

    public static DataTable GetHistory(DateTime from, DateTime to, List<string> types) {  .. } 

    and then pass in a list that looked like these (for example)

    List<string> types =    new List<string> { 'paramedics' };  or   List<string> types =    new List<string> { 'paramedics', 'police' }; 

    Then you could adapt your query to use the SQL IN statement in your where clause. Next convert the list of strings into a comma separated string like

    string values = ''paramedics', 'police'' 

    A simple way to create the values variable is to use

    string values = string.Empty;             types.ForEach(s =>             {                if (!string.IsNullOrEmpty(values))                    values += ',';                values += string.Format(''{0}'', s);              }); 

    By the way you could use a parameterized command to avoid SQL injection. Once you have the string you can simply do

    string select =  'SELECT call_time, location, emergency_type where call_time between @from AND @to AND emergency_type IN ' + values 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 134k
  • Answers 134k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer First you need to change the current table to a… May 12, 2026 at 6:50 am
  • Editorial Team
    Editorial Team added an answer Some references, At MSDN blogs -- Writing IE AddOns, The… May 12, 2026 at 6:50 am
  • Editorial Team
    Editorial Team added an answer the FullName property gets you the full path of the… May 12, 2026 at 6:50 am

Related Questions

I have a database with a table named shoppingcarts . this table has the
I have a table in my Postgres database with columns named type, desc, and
I have a web application that uses a fairly large table (millions of rows,
I know there are other naming convention discussions, but the ones I saw were

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.