Pregunta

Estoy aprendiendo SQLite y no puedo hacer que mis parámetros se compilen correctamente en el comando. Cuando ejecuto el siguiente código:

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();

Obtengo una excepción SQLite. Al inspeccionar el texto de texto, descubro que todo lo que estoy haciendo no está agregando correctamente los parámetros: INSERT INTO [StringData] VALUE (?,?)

¿Alguna idea de lo que me estoy perdiendo?

Gracias

¿Fue útil?

Solución

Pruebe VALUES en lugar de VALUE .

Otros consejos

Intente un enfoque diferente, asigne un nombre a sus campos en la consulta y a los parámetros en la consulta:

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));
...
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top