Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# SQLite准备的语句在SQLiteDateReader上不工作?_C#_Sqlite_Prepared Statement - Fatal编程技术网

C# SQLite准备的语句在SQLiteDateReader上不工作?

C# SQLite准备的语句在SQLiteDateReader上不工作?,c#,sqlite,prepared-statement,C#,Sqlite,Prepared Statement,这是我的密码 SQLiteConnection connection = new SQLiteConnection("Data Source=userData.dat;version=3;"); connection.Open(); SQLiteCommand cmd = connection.CreateCommand(); cmd.CommandText = "SELECT * FROM tags WHERE tags_tags LIKE '%@tags_tags%' ORDER by

这是我的密码

SQLiteConnection connection = new SQLiteConnection("Data Source=userData.dat;version=3;");
connection.Open();

SQLiteCommand cmd = connection.CreateCommand();

cmd.CommandText = "SELECT * FROM tags WHERE tags_tags LIKE '%@tags_tags%' ORDER by tags_id DESC LIMIT 0, 100";
cmd.Parameters.Add("@tags_tags", DbType.String);
cmd.Parameters["@tags_tags"].Value = tags;


SQLiteDataReader reader = cmd.ExecuteReader();
var _sql = cmd.CommandText;
MessageBox.Show(_sql);//still shows "SELECT * FROM tags WHERE tags_tags LIKE '%@tags_tags%' ORDER by tags_id DESC LIMIT 0, 100"
我还使用了
cmd.Parameters.AddWithValue
,但不起作用…
错在哪里

连接字符串中的参数,例如

LIKE '%' || @tags_tags || '%'

您使用单引号将参数括起来,从而使其成为一个值。删除单引号并在参数值上连接百分比符号

LIKE @tags_tags
在你的参数中

cmd.Parameters["@tags_tags"].Value = '%' + tags + '%';

您是否尝试捕获任何异常?没有任何错误。唯一的问题是我的查询仍然没有准备好。您无法在命令文本中看到包含替换变量的完整查询。您必须启动SQL Profiler并记录发送到服务器的查询。在那里你将有完全相同的查询,但也定义了变量。真的很好!这正是我想要的:x