SQLite 多参数插入注意事项 insert multiple parameters
发布时间:2020-12-12 23:35:24 所属栏目:百科 来源:网络整理
导读: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
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. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |