0

Hi. Im having some problems to understand how to make search in SQL database
actually I use this code

 DV.RowFilter = String.Format("name Like '%{0}%'", TextBox1.Text)
 DataGridView1.DataSource = DV

and it work, but Im trying to show in a datagrid view results from the table but searched by 2 or more words

for example in table1 I have all the names of people in my city and their current jobs,

and in datagrid view I want to show all people who's called Andrea and in the some time is a cop (or something else)

any suggestion?

3
Contributors
5
Replies
34
Views
1 Year
Discussion Span
Last Post by Reverend Jim
0

also typed this here too because did not wanted to create an other topic,

how to make the software check if in textbox is a upper letter. something like: "me and Ana are going in beach" how to make the app understand there is word Ana?

Edited by altjen

0

The actual query would look something like

SELECT * FROM tablename
 WHERE name LIKE '%Andrea%'
   AND occupation IN ('cop','butcher','baker')
0

wouldnt it look for for cop, butcher and baker in the some time?

0

If you wanna make it two words from two different text boxes you use

 DV.RowFilter = String.Format("name Like '%{0}%' OR name Like '%{1}%'", TextBox1.Text,TextBox2.Text)

If you wanna search a string theres an InStr function that can help you with that. I don't know about identifying a capital letter.

And like Reverend Jim said. You need to make use of the IN keyword.

0

I want to show all people who's called Andrea and in the some time is a cop (or something else)

If you want only cop then just do

SELECT * FROM tablename
 WHERE name LIKE '%Andrea%'
   AND occupation = 'cop'

but "(or something else)" implies you are interested in more than just cop.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.