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. .NET (Core and Framework)
  4. Why am I getting insufficient parameters supplied

Why am I getting insufficient parameters supplied

Scheduled Pinned Locked Moved .NET (Core and Framework)
salesquestion
5 Posts 5 Posters 2 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
    Adrian Rowlands
    wrote on last edited by
    #1

    using (SQLiteCommand cmd = conn.CreateCommand())
    {
    try
    {

         cmd.CommandText = @"SELECT \* FROM.  customer WHERE lastname = @setName";
    
        cmd.Parameters.AddWithValue("@setName", txt\_name.Text);
    
        da\_Customer = new SQLiteDataAdapter(cmd.CommandText, conn);
         dt\_Customer = new DataTable();
        da\_Customer.Fill(dt\_Customer);
        dgv\_customer.DataSource = dt\_Customer;
        }
         catch (Exception ex)
       {
        MessageBox.Show(ex.Message);
         }
         }
    

    I get insufficient parameters supplied with this block of code, any ideas why?

    L D Richard DeemingR C 4 Replies Last reply
    0
    • A Adrian Rowlands

      using (SQLiteCommand cmd = conn.CreateCommand())
      {
      try
      {

           cmd.CommandText = @"SELECT \* FROM.  customer WHERE lastname = @setName";
      
          cmd.Parameters.AddWithValue("@setName", txt\_name.Text);
      
          da\_Customer = new SQLiteDataAdapter(cmd.CommandText, conn);
           dt\_Customer = new DataTable();
          da\_Customer.Fill(dt\_Customer);
          dgv\_customer.DataSource = dt\_Customer;
          }
           catch (Exception ex)
         {
          MessageBox.Show(ex.Message);
           }
           }
      

      I get insufficient parameters supplied with this block of code, any ideas why?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      At what line? It says so in the exception, so why can't you?

      Bastard Programmer from Hell :suss: "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

      1 Reply Last reply
      0
      • A Adrian Rowlands

        using (SQLiteCommand cmd = conn.CreateCommand())
        {
        try
        {

             cmd.CommandText = @"SELECT \* FROM.  customer WHERE lastname = @setName";
        
            cmd.Parameters.AddWithValue("@setName", txt\_name.Text);
        
            da\_Customer = new SQLiteDataAdapter(cmd.CommandText, conn);
             dt\_Customer = new DataTable();
            da\_Customer.Fill(dt\_Customer);
            dgv\_customer.DataSource = dt\_Customer;
            }
             catch (Exception ex)
           {
            MessageBox.Show(ex.Message);
             }
             }
        

        I get insufficient parameters supplied with this block of code, any ideas why?

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

        First, clean up your code indentation. It makes debugging your code easier and reduces the number of bugs in your code. Next, in your SQL statement, get rid of the period you have on the FROM clause. Then get rid of the * and replace it with the fields you want. Trust me, using "SELECT *" is NOT a habit you want to get into.

        SELECT _fieldList_, ... FROM customer WHERE lastname=@setName";
        

        After that, why are you creating a SqlCommand object only to throw it out and never use it with the DataAdapter? The SqlDataAdapter will take a SqlCommand object as a parameter, but you just pass in the SQL statement (.Text property) of the command you built, effectively ignoring the parameter object you built. Your code should be this:

        using (SQLiteCommand cmd = conn.CreateCommand())
        {
        try
        {
        cmd.CommandText = @"SELECT * FROM customer WHERE lastname = @setName";

            cmd.Parameters.AddWithValue("@setName", txt\_name.Text);
        
            da\_Customer = new SQLiteDataAdapter(cmd);
            dt\_Customer = new DataTable();
            da\_Customer.Fill(dt\_Customer);
            dgv\_customer.DataSource = dt\_Customer;
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
        

        }

        Also, it seems you're using class global data objects, "da_Customer", "dt_Customer", ... This is a REALLY BAD IDEA and will get you into trouble in the future with bugs that are really difficult to find. You should have individual methods that will return data, creating and disposing their own database objects, more like this:

        public DataTable GetCustomerTableFromLastName(string lastName)
        {
        using (SQLiteConnection conn = new SQLiteConnection(CONNECTIONSTRING))
        {
        SQLiteCommand comm = conn.CreateCommand();

            cmd.CommandText = @"SELECT firstname, lastname, something, somethingElse FROM customer WHERE lastname = @setName";
        
            cmd.Parameters.AddWithValue("@setName", txt\_name.Text);
        
            SQLiteDataAdapter adpat = new SQLiteDataAdapter(cmd);
            DataTable tableResult = new DataTable();
            adapt.Fill(tableResult);
        
            return tableResult;
        }
        

        }

        But, even though this is an improvement, it still falls way short of production quality code.

        Asking questions is a skill CodeProject Forum Gui

        1 Reply Last reply
        0
        • A Adrian Rowlands

          using (SQLiteCommand cmd = conn.CreateCommand())
          {
          try
          {

               cmd.CommandText = @"SELECT \* FROM.  customer WHERE lastname = @setName";
          
              cmd.Parameters.AddWithValue("@setName", txt\_name.Text);
          
              da\_Customer = new SQLiteDataAdapter(cmd.CommandText, conn);
               dt\_Customer = new DataTable();
              da\_Customer.Fill(dt\_Customer);
              dgv\_customer.DataSource = dt\_Customer;
              }
               catch (Exception ex)
             {
              MessageBox.Show(ex.Message);
               }
               }
          

          I get insufficient parameters supplied with this block of code, any ideas why?

          Richard DeemingR Offline
          Richard DeemingR Offline
          Richard Deeming
          wrote on last edited by
          #4

          Adrian Rowlands wrote:

          da_Customer = new SQLiteDataAdapter(cmd.CommandText, conn);

          Because you're passing the command text to the data adapter, not the command. The data adapter will create a new command using that command text, and none of the parameters you've added to cmd will be copied across. Pass in the command object instead:

          da_Customer = new SQLiteDataAdapter(cmd);

          But pay attention to Dave's advice (above[^]) as well.


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

          1 Reply Last reply
          0
          • A Adrian Rowlands

            using (SQLiteCommand cmd = conn.CreateCommand())
            {
            try
            {

                 cmd.CommandText = @"SELECT \* FROM.  customer WHERE lastname = @setName";
            
                cmd.Parameters.AddWithValue("@setName", txt\_name.Text);
            
                da\_Customer = new SQLiteDataAdapter(cmd.CommandText, conn);
                 dt\_Customer = new DataTable();
                da\_Customer.Fill(dt\_Customer);
                dgv\_customer.DataSource = dt\_Customer;
                }
                 catch (Exception ex)
               {
                MessageBox.Show(ex.Message);
                 }
                 }
            

            I get insufficient parameters supplied with this block of code, any ideas why?

            C Offline
            C Offline
            C0ding_j3ff
            wrote on last edited by
            #5

            In my opinion, this could probably have a lot to do with the software you are currently using.

            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