Windows Form Error: The parameterized query expects the parameter @members which was not supplied

Last Reply 17 days ago By dharmendr

Posted 17 days ago

Greetings again experts,

I am working with Windows Forms DataGridView control and trying to update a record with selected value from two comboboxes but I keep getting the following error:

The parameterized query '(@transid nvarchar(1),@members nvarchar(4000),@Amount nvarchar(8' expects the parameter '@members', which was not supplied.

A bit more details.

I have two comboboxes; one is called paymentType and the other is called txtmemberName.

These comboboxes are dynamically populated from the database.

When inserting new records into the Transactions table, the IDs of these comboboxes are inserted into the transactions table.

This works fine.

When displaying records, we join the look up tables with Transactions table to display the correct records.

This works great as well.

The issue we are having is when updating records in Transactions table and we try to update values for any of the comboboxes, say @members which is associated with txtmemberName combobox, we run into the error described above.

Any ideas how to solve this problem?

        private void btnUpdate_Click_1(object sender, EventArgs e)
            string constr = ConfigurationManager.ConnectionStrings["Members"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);
            SqlCommand cmdupdate = new SqlCommand("Update Transactions set memberID=@members, Amount=@Amount,AmountPaid=@AmountPaid, Balance=@Balance, TypeID=@ptype FROM Transactions t INNER JOIN Members m ON t.memberID = m.memberID INNER JOIN PaymentTypes p ON t.TypeID = p.PaymentTypeID Where (TransactionID=@transid)", conn);
            cmdupdate.Parameters.AddWithValue("@transid", transactionid.Text);
            cmdupdate.Parameters.AddWithValue("@members", txtmemberName.SelectedValue);
            cmdupdate.Parameters.AddWithValue("@Amount", annual_dues.Text);
            cmdupdate.Parameters.AddWithValue("@AmountPaid", Amt_Paid.Text);
            cmdupdate.Parameters.AddWithValue("@Balance", Amt_Owed.Text);
            cmdupdate.Parameters.AddWithValue("@ptype", paymentType.SelectedValue);
            // cmd.Parameters.AddWithValue("@registration_date", registration_date.Text);