I get the error SQLite error Insufficient parameters supplied to the command when running an insert statement in my program. However, I've got it narrowed down to it will only occur if I try to insert data into two different tables in succession. Meaning I insert data into one and everything in the method is diposed of since I am using USING statements.
This error won't occur if I insert data into one table stop debugging, rebuild my solution and then insert into the other table.
Anyone have any ideas? Like I said everything is encapsulated in using statements so I don't know what is getting held in memory.
Here is my method:
public static void SQLiteTableINSERT(string tableName)
{
using (SQLiteConnection Conn = new SQLiteConnection(SQLiteConn.Conn))
{
using (SQLiteTransaction sqliteTrans = Conn.BeginTransaction())
{
using (SQLiteCommand cmd = Conn.Cre开发者_StackOverflow中文版ateCommand())
{
cmd.CommandText = PrepareInsert(tableName);
for (int i = 0; i < LocalDataSet.LocalDs.Tables[0].Rows.Count; ++i)
{
foreach (DataColumn col in LocalDataSet.LocalDs.Tables[0].Columns)
{
string temp = LocalDataSet.LocalDs.Tables[0].Rows[i][col, DataRowVersion.Current].ToString();
cmd.Parameters.AddWithValue("@" + col.ColumnName, temp);
}
cmd.ExecuteNonQuery();
}
}
sqliteTrans.Commit();
}
}
SQLite.SQLiteConn.Conn.Close();
}
Any ideas would be great. Thanks.
I think you need to be using the tableName in the loop, assuming that the tables don't have the same schema.
The command is prepared for the table with name tableName, but the params you are adding are always from Tables[0], try Tables[tablename]
精彩评论