| |

VerySource

 Forgot password?
 Register
Search
View: 1234|Reply: 7

(C#) How to query multiple conditions in one page

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-12-14 16:30:02
| Show all posts |Read mode
I set up query conditions with four DropDownLists in one page, but how do I write the code? Is it too cumbersome to use IF? Please advise me
Reply

Use magic Report

0

Threads

64

Posts

45.00

Credits

Newbie

Rank: 1

Credits
45.00

 China

Post time: 2020-12-14 16:45:01
| Show all posts
If you want to judge, only IF and Switch...Case
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 Japan

Post time: 2020-12-15 07:15:02
| Show all posts
if (this.Drpcondition.SelectedIndex> 0)
        {
            string cdition = this.Drpcondition.SelectedValue;
            string Condition="";

            switch (cdition)
            {
                case "Post user":
                    Condition = "select * from MQ_ALlPhoto where UserName like'%" + this.txtcondotion.Text.Trim() + "%'";
              
                    break;

                case "title":
                    Condition = "select * from MQ_ALlPhoto where Topic like'%" + this.txtcondotion.Text.Trim() + "%'";
                 
                    break;

         
            }
}
Reply

Use magic Report

2

Threads

17

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-12-15 09:00:01
| Show all posts
Suck with or
select * from ... where ...like ... or like .... or like ..... or like ...
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-12-15 09:45:01
| Show all posts
Jump statements such as if or switch are basically indispensable.
Generally, all query conditions are read into a class, a dynamic string is added to a pseudo SQL statement, and the dynamic string is finally included in the SQL statement according to the judgment condition.
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-12-19 17:15:01
| Show all posts
Thank you, everyone, now I use "select * from ... where ...like ... and like .... and like ....." to achieve.
But there is a new problem: how to implement fuzzy query if there is no choice?
Reply

Use magic Report

0

Threads

29

Posts

19.00

Credits

Newbie

Rank: 1

Credits
19.00

 China

Post time: 2020-12-20 06:15:01
| Show all posts
The value of dropdownlist is an arraylist object, the key value. You can set the value of the first option as the default query condition.
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-12-20 09:30:01
| Show all posts
You can make them mandatory, otherwise they will not be executed
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list