Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding parameters in SQLite with C#

Im just learning SQLite and I can't get my parameters to compile into the command properly. When I execute the following code:

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

I get a SQLite Exception. Upon inspecting the CommandText I discover that whatever I'm doing is not correctly adding the parameters: INSERT INTO [StringData] VALUE (?,?)

Any ideas what I'm missing?

Thanks

like image 344
Brian Sweeney Avatar asked Apr 30 '09 21:04

Brian Sweeney


1 Answers

Try a different approach, naming your fields in the query and naming the parameters in the query:

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)); ... 
like image 118
Björn Avatar answered Sep 18 '22 15:09

Björn