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!
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();
}
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.