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?

Recommended Answers

All 5 Replies

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?

The actual query would look something like

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

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

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.