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

前端之家收集整理的这篇文章主要介绍了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 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.

猜你在找的Sqlite相关文章