Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to solve this Error in SQLite?

How to solve this Error in SQLite?

Scheduled Pinned Locked Moved C#
databasehelpsqlitedebuggingtutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Alex Dunlop
    wrote on last edited by
    #1

    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.

    OriginalGriffO D 2 Replies Last reply
    0
    • A Alex Dunlop

      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.

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • A Alex Dunlop

        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.

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #3

        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!

        "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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups