简体   繁体   中英

asp.net c# Multiple search from tables

I want to make a search function but I need to search from 1 textbox against multiple columns. For example I have:

string select="Select * From tableName where(Name like'%" + texbox1.text.ToString() + "'";
sqldatasource1.selectcommand = select;

via that code I can only search in table Name. How can I extend this to work against many columns?

Sql database 2008 Thanks

I'm not sure if I understand your question correctly. Are you asking how to search over multiple columns? If so, your where-clause is simply:

where Column1 like '%'" + textbox1.text.ToString() + " OR Column2 like '%'" + textbox1.text.ToString(); // ... and so on

But please don't build your query string as shown since this exposes you to an SQL injection attack! Use named parameters instead.

字符串查询=“从ProductDetails中选择*,其中ProductName类似于'” + SearchTextBox.Text +“%'” +“或ProductType类似于'” + SearchTextBox.Text +“%'”;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM