Click here to Skip to main content
15,903,012 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi my name Qasem, Im from Afghanistan,
I have a db for student in school and for a reason like we have student with the same name and fathers name, when i search only by the name it shows me 100 name, then search with just fathers name it shows me 50 name, how can i create 3 txt box one for name one for father name and another for like student id and when click to search these three box work together and search.
I hope you know my problem and help me.
thank you so much.

What I have tried:

in you tube finding nothing to show me how i do this.
Posted
Updated 18-Aug-17 19:47pm

1 solution

Simple: create a SELECT statement which uses AND clauses in the WHERE statement:
SQL
SELECT ... WHERE studentName = 'John' AND fatherName = 'Mike'
This causes the DB to only return rows where both conditions are true. All you have to do is replace the fixed strings with the text box content.

But do note two things:
1) Since the StudentID will be unique (or it isn't an ID value, and you have something very, very wrong in your system) if you include that in your WHERE criteria via an AND you will only get one row or none - the rest of the criteria are pretty much irrelevant.
2) Never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead. Google will show you how to do that (but it'll be slightly different depending on exactly what you are using to access the DB, so I can't give you an example).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900