【发布时间】:2010-09-09 16:00:21
【问题描述】:
在我的模型中,我有一个字符串 txtSearche,其值来自如下文本框:
“大家好”
如何编写我的语句动态添加WHERE text LIKE '%Text%' 为每个单词附加?大概是 3 次:
WHERE Text LIKE '%@Text%'";
这是我的代码:
string[] wordsFromTxtSearche = txtSearche.Split(' ');
SqlCommand cmd = new SqlCommand();
cmd.Connection = connection;
cmd.CommandType = System.Data.CommandType.Text;
cmd.CommandText = @"SELECT * "
+ " FROM ForumThread "
+ " WHERE Text LIKE '%@Text%'";
cmd.Parameters.Add(new SqlParameter("@Text", txtSearche));
我想我需要在 For 循环的帮助下完成,但我不知道怎么做。请帮帮我
【问题讨论】:
标签: c# asp.net-mvc sql