How to solve this Error in SQLite?
-
I use this code in a button to save data into a SQLite file:
//path of data base string conString = @"URI=file:" + Application.StartupPath + "\\\\DataBase.db"; //database created in debug folder
SQLiteConnection con = new SQLiteConnection(conString);
SQLiteCommand cmd = new SQLiteCommand(con);con.Open(); try { cmd.CommandText = "INSERT INTO FileInfo(EqpCode, EqpName, FileName) VALUES(@EqpCode, @EqpName, @FileName)"; for (int i = 0; i < myTable02.Rows.Count; i++) { string EqpCode = myTable02.Rows\[i\]\[0\].ToString(); string EqpName = myTable02.Rows\[i\]\[1\].ToString(); string FileName = myTable02.Rows\[i\]\[2\].ToString(); cmd.Parameters.AddWithValue(@EqpCode, EqpCode); cmd.Parameters.AddWithValue(@EqpName, EqpName); cmd.Parameters.AddWithValue(@FileName, FileName); cmd.ExecuteNonQuery(); } con.Close(); } catch (Exception) { throw; }
The error is thrown in cmd.ExecuteNonQuery() line: System.Data.SQLite.SQLiteException: 'unknown error Insufficient parameters supplied to the command' Please help me.
-
I use this code in a button to save data into a SQLite file:
//path of data base string conString = @"URI=file:" + Application.StartupPath + "\\\\DataBase.db"; //database created in debug folder
SQLiteConnection con = new SQLiteConnection(conString);
SQLiteCommand cmd = new SQLiteCommand(con);con.Open(); try { cmd.CommandText = "INSERT INTO FileInfo(EqpCode, EqpName, FileName) VALUES(@EqpCode, @EqpName, @FileName)"; for (int i = 0; i < myTable02.Rows.Count; i++) { string EqpCode = myTable02.Rows\[i\]\[0\].ToString(); string EqpName = myTable02.Rows\[i\]\[1\].ToString(); string FileName = myTable02.Rows\[i\]\[2\].ToString(); cmd.Parameters.AddWithValue(@EqpCode, EqpCode); cmd.Parameters.AddWithValue(@EqpName, EqpName); cmd.Parameters.AddWithValue(@FileName, FileName); cmd.ExecuteNonQuery(); } con.Close(); } catch (Exception) { throw; }
The error is thrown in cmd.ExecuteNonQuery() line: System.Data.SQLite.SQLiteException: 'unknown error Insufficient parameters supplied to the command' Please help me.
cmd.Parameters.AddWithValue(@EqpCode, EqpCode);
cmd.Parameters.AddWithValue(@EqpName, EqpName);
cmd.Parameters.AddWithValue(@FileName, FileName);You need to enclose the parameter names in quotes. They are the strings that identify which parameter they go to in the SQL statement.
cmd.Parameters.AddWithValue("@EqpCode", EqpCode);
cmd.Parameters.AddWithValue("@EqpName", EqpName);
cmd.Parameters.AddWithValue("@FileName", FileName);Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave Kreskowiak -
I use this code in a button to save data into a SQLite file:
//path of data base string conString = @"URI=file:" + Application.StartupPath + "\\\\DataBase.db"; //database created in debug folder
SQLiteConnection con = new SQLiteConnection(conString);
SQLiteCommand cmd = new SQLiteCommand(con);con.Open(); try { cmd.CommandText = "INSERT INTO FileInfo(EqpCode, EqpName, FileName) VALUES(@EqpCode, @EqpName, @FileName)"; for (int i = 0; i < myTable02.Rows.Count; i++) { string EqpCode = myTable02.Rows\[i\]\[0\].ToString(); string EqpName = myTable02.Rows\[i\]\[1\].ToString(); string FileName = myTable02.Rows\[i\]\[2\].ToString(); cmd.Parameters.AddWithValue(@EqpCode, EqpCode); cmd.Parameters.AddWithValue(@EqpName, EqpName); cmd.Parameters.AddWithValue(@FileName, FileName); cmd.ExecuteNonQuery(); } con.Close(); } catch (Exception) { throw; }
The error is thrown in cmd.ExecuteNonQuery() line: System.Data.SQLite.SQLiteException: 'unknown error Insufficient parameters supplied to the command' Please help me.
Look at your code. Instead of inserting a new row each time, you are adding subsequent rows to the existing parameters set by the previous iteration. So the first row passes 3 pieces of data, the second passes 6, the third 9, and so on ...
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!