使用SQLite,如何搜索包含'?
的字符这可以找到布鲁斯和棒球:
string stCmdString = "SELECT fstInfo FROM PadTable WHERE fstInfo LIKE '%bruce%' AND fstInfo LIKE '%baseball%'"
不确定如何找到布鲁斯和棒球。
答案 0 :(得分:2)
你用另一个撇号逃避了撇号:
string stCmdString = "SELECT fstInfo FROM PadTable WHERE fstInfo LIKE '%bruce''s%' AND fstInfo LIKE '%baseball%'"
答案 1 :(得分:1)
参数功能允许使用具有'在这个词中。
using (System.Data.SQLite.SQLiteCommand sqliteCmd = sqliteConnection.CreateCommand())
{
sqliteCmd.CommandText = "SELECT" + stFieldNames + "FROM " + stTableName + " WHERE " + stLikeFieldName + " LIKE '%' || @p0 || '%'";
sqliteCmd.Parameters.Add(new SQLiteParameter("@p0", liststLikeFieldValue[0]));
for (int iii = 1; iii < liststLikeFieldValue.Count; iii++)
{
sqliteCmd.CommandText += " AND " + stLikeFieldName + " LIKE '%' || @p" + iii.ToString() + " || '%'";
sqliteCmd.Parameters.Add(new SQLiteParameter("@p" + iii.ToString(), liststLikeFieldValue[iii]));
}