Click here to Skip to main content
15,890,825 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to search some content in multiple rows, like :-

i used this code for searching text similar to the ENTERED text in textbox3 in column 1, but i want that it should also display the record with 2nd column having similar data.

DA.SelectCommand = new SqlCommand("select * from SEATING where STATUS1 like '" + textBox3.Text + "%' ", CS);




All i want is the above code should also display records in datagridview with text appearing similar in STATUS2 , STATUS3 , STATUS4 columns.....

What I have tried:

i have tried using 'and' or 'or' or placing ',' between 2 columns but it dint work
Posted
Updated 24-Jun-17 7:03am

Not a solution to your question, but another problem you have.
Never build an SQL query by concatenating strings. Sooner or later, you will do it with user inputs, and this opens door to a vulnerability named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input a name like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability, and the crash is the least of the problems, a malicious user input and it is promoted to SQL commands with all credentials.
SQL injection - Wikipedia[^]
SQL Injection[^]
 
Share this answer
 
 
Share this answer
 
v2
Comments
chinu1d 24-Jun-17 9:54am    
can you give an example??
chinu1d 24-Jun-17 9:58am    
it gives this error

An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll

Additional information: Cannot use a CONTAINS or FREETEXT predicate on table or indexed view 'SEATING' because it is not full-text indexed.
RickZeeland 24-Jun-17 10:07am    
You will first have to prepare your database, see: https://docs.microsoft.com/en-us/sql/relational-databases/search/get-started-with-full-text-search

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