使用C#在SQLite中添加参数
-
03-07-2019 - |
题
我刚刚学习SQLite,我无法正确编译命令。当我执行以下代码时:
this.command.CommandText = "INSERT INTO [StringData] VALUE (?,?)";
this.data = new SQLiteParameter();
this.byteIndex = new SQLiteParameter();
this.command.Parameters.Add(this.data);
this.command.Parameters.Add(this.byteIndex);
this.data.Value = data.Data;
this.byteIndex.Value = data.ByteIndex;
this.command.ExecuteNonQuery();
我得到了SQLite异常。在检查CommandText时,我发现无论我做什么都没有正确添加参数: INSERT INTO [StringData] VALUE(?,?)
我缺少什么想法?
由于
解决方案
尝试 VALUES
而不是 VALUE
。
其他提示
尝试不同的方法,在查询中命名字段并在查询中命名参数:
this.command.CommandText = "INSERT INTO StringData (field1, field2) VALUES(@param1, @param2)";
this.command.CommandType = CommandType.Text;
this.command.Parameters.Add(new SQLiteParameter("@param1", data.Data));
this.command.Parameters.Add(new SQLiteParameter("@param2", data.ByteIndex));
...
不隶属于 StackOverflow