如何在多列中搜索 [英] How do I search in multiple columns

查看:80
本文介绍了如何在多列中搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在多行中搜索一些内容,例如: -



i使用此代码搜索类似于第1列中textbox3中的ENTERED文本的文本,但是我希望它也应该显示第二列具有相似数据的记录。



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);









我想要的就是上面的代码还应该在datagridview中显示记录,其中的文本在STATUS2,STATUS3,STATUS4列中显示类似的内容.....



我尝试了什么:



i尝试在2列之间使用'和'或'或'或'','但是它工作





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

推荐答案

不是你问题的解决方案,而是你遇到的另一个问题。

永远不要通过连接字符串来构建SQL查询。迟早,您将使用用户输入来执行此操作,这会打开一个名为SQL注入的漏洞,这对您的数据库很容易并且容易出错。

名称中的单引号你的程序崩溃。如果用户输入像Brian O'Conner这样的名称可能会使您的应用程序崩溃,那么这是一个SQL注入漏洞,崩溃是最少的问题,恶意用户输入,并且它被提升为具有所有凭据的SQL命令。

SQL注入 - 维基百科 [ ^ ]

SQL注入 [ ^ ]
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[^]


如果使用SQL Server,则可以使用 Freetext ,参见:使用SQL Server FREETEXT命令扩展搜索功能 [ ^ ]

另见:全文搜索入门| Microsoft Docs [ ^ ]
If you use SQL Server, you can use Freetext, see: Expand search capabilities with the SQL Server FREETEXT command[^]
Also see: Get Started with Full-Text Search | Microsoft Docs[^]


这篇关于如何在多列中搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆