【发布时间】:2015-06-09 11:59:34
【问题描述】:
谁能帮我解决我的问题?
我有一个最大长度的字符串数组。我想将我的所有字符串数组元素与单个 SQL 查询进行比较。我该怎么做?
string[] new = searchtext;
select Qid from questions where qdescriptions like string[0],string[1],string[2]
字符串数组长度不是固定的,是动态的。
例如:我的搜索字符串是“管理员登录错误”
然后我把它分成
admin
login
error
作为三个部分。我的预期结果应该包含数据库中的所有这三个字符串
这样
Admin post this;
password change for login;
the error database;
希望你能理解。结果应该包含我在单个搜索查询中的所有搜索字符串..
C#代码:
public void searchdetails(string[] searchwords) {
SqlConnection con = new SqlConnection();
con.ConnectionString = connection; con.Open();
string[] soldesc = searchwords;
int i = 0;
if (soldesc.Length == 1) {
string query1 = "select Qid from Questions where Qdescription like '% " + soldesc[i] + " %'";
}
SqlCommand cmds = new SqlCommand(query1, con); cmds.ExecuteNonQuery();
【问题讨论】:
-
请提供更多细节
-
现在看..ii 更新了
-
每个字符串需要一个 LIKE,在 LIKE 之间放置 OR。
-
sql 中的字符串数组?
-
您使用的是哪种 dbms 产品?
标签: sql sql-server where sql-like