The following code works flawlessly:
public int put_item(Item xitem)
{
using (SQLiteTransaction transaction = my_connection.BeginTransaction())
{
using (SQLiteCommand command = new SQLiteCommand(my_connection))
{
SQLiteParameter item_id = command.CreateParameter();
item_id.Value = xitem.my_id;
SQLiteParameter item_name = command.CreateParameter();
item_name.Value = xitem.my_name;
SQLiteParameter item_icon = command.CreateParameter();
item_icon.Value = xitem.my_icon;
SQLiteParameter item_level = command.CreateParameter();
item_level.Value = xitem.my_level;
SQLiteParameter item_quality = command.CreateParameter();
item_quality.Value = xitem.my_quality;
SQLiteParameter item_type = command.CreateParameter();
item_type.Value = xitem.my_type;
command.CommandText = "insert into items (id, name, icon, level, quality, type) values (?1, ?2, ?3, ?4, ?5, ?6);";
command.Parameters.Add(item_id);
command.Parameters.Add(item_name);
command.Parameters.Add(item_icon);
command.Parameters.Add(item_level);
command.Parameters.Add(item_quality);
command.Parameters.Add(item_type);
command.ExecuteNonQuery();
}
transaction.Commit();
}
return 0;
}
If I change the query to either of these two:
command.CommandText = "insert into items (id, name,
icon, level, quality, type) values (?1, ?2, ?3, ?4, ?5, ?6);";
command.CommandText = "insert into items (id, name,
icon, level, quality, type) values (:a, :b, :c, :d, :e, :f);";
Then I get an exception from the ExecuteNonQuery() function call:
An unhandled exception of type 'System.Data.SQLite.SQLiteException' occurred in System.Data.SQLite.dll
Additional information: SQLite error
Insufficient parameters supplied to the command
(Interestingly enough I had the opposite problem when I was using the C library directly in another project. I couldn't get queries with only ?'s to work.)