SQLite 多参数插入注意事项 insert multiple parameters

1.) Do not reuse a parameter

2.)  VALUES(@str, @new) ParameterName="@str." ParameterName="@new."
As the error indicates, you are using the parameters @str and @new and adding two different parameters. Read the error message, it is there for a reason and told you exactly what is wrong!

3.) Here is how I would write it (in this context).

using (SQLiteConnection cnn = new SQLiteConnection("Data Source=C://EEk.db"))
using (SQLiteCommand cmd = Database.CreateCommand())
{
    cmd.CommandText = "INSERT INTO test (Field1,fname) VALUES(@str, @new)";
    cmd.Parameters.AddWithValue("@str", textBox1.Text);
    cmd.Parameters.AddWithValue("@new", textBox2.Text);

    cnn.Open();
    cmd.ExecuteNonQuery();
    cnn.Close();
}

While you can use DbConnection and DbCommand and make a factory pattern sort of implementation (which I doubt is going on here...) I suggest you do not. Use the SqliteConnection, SqliteCommand, etc. The provider specific objects generally have features that make coding easier. In this case, the AddWithValue method.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值