why am i getting insufficient parameters supplied to the command

Adrian 1 Reputation point
2021-03-25T09:04:31.717+00:00

i have a windows forms application and using sqlite to connect to a database, im trying to display the contents of a table in a datagridview, it works if i dont use parameters but if i set up parameters then i get the error message

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

                    cmd.Parameters.Add("LastName", DbType.String).Value = 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);
                }


            }
Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,821 questions
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,654 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,205 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Viorel 111.8K Reputation points
    2021-03-25T09:35:10.987+00:00

    Try this modification:

    da_Customer = new SQLiteDataAdapter(cmd);
    
    0 comments No comments