Search code examples
c#parametersoledbupdatingaceoledb

No value given for required parameters


I am trying to make a button that updates account nickname using the account number but Im getting an error.

enter image description here

  private void change_nickname_Click(object sender, EventArgs e)
    {
        try
        {
            connection.Open();
            OleDbCommand command = new OleDbCommand();
            command.Connection = connection;
            string query = "update customers set [CustomerCode]='" + customercode.Text + "',[CustomerName]='" + customername.Text + "',[Address]='" + customeraddress.Text + "',[PhoneNumber]='" + customerphone.Text + "',[Account]='" + Account + "',[AccountNickname]='" + accountnickname.Text + "',[Overdraft]='" + overdraft.Text + "' where AccountNumber=" + accountnumber.Text + "";
            MessageBox.Show(query);
            command.CommandText = query;

            command.ExecuteNonQuery();
            MessageBox.Show("Data updated successfuly!");
            connection.Close();
        }
        catch (Exception ex)
        {
            MessageBox.Show("Error: " + ex);
        }
        connection.Close();
    }

Solution

  • Yeah the problem was solved guys thank for all the help. The problem was here.

    where AccountNumber=" + accountnumber.Text + "";
            MessageBox.Show(query);
    

    I changed this to

    where AccountNumber='" + accountnumber.Text + "'";
            MessageBox.Show(query);
    

    And it worked somehow.