0

The error message returns with that it expected 0 arguments but it got 6

DELIMITER //

CREATE Procedure customer_reg()

BEGIN

INSERT INTO tblcustomers

(customerName, contactNo, Email, Address, Password, DoB)

VALUES

(AES_ENCRYPT(@customerName,'name'),

AES_ENCRYPT(@contactNo, 'con'),

AES_ENCRYPT(@Email,' email'),

AES_ENCRYPT(@Address, 'add'),

AES_ENCRYPT(@Password, 'pass'),

AES_ENCRYPT(@DoB,'dob'));

END //

DELIMITER ;

I'm using the query above to create a procedure customer_reg in order to use customer_reg in a c# form but all values being inserted in the database turn into null values:

 if (MessageBox.Show("Register as a customer?", "CONFIRM", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                try
                {
                    con.Open();
                    MySqlCommand cmd = new MySqlCommand("customer_reg", con);
                    cmd.CommandType = CommandType.StoredProcedure;

                    // Add parameters to the command
                    cmd.Parameters.AddWithValue("@customerName", txtName.Text);
                    cmd.Parameters.AddWithValue("@contactNo", txtPhone.Text);
                    cmd.Parameters.AddWithValue("@Email", txtEmail.Text);
                    cmd.Parameters.AddWithValue("@Address", txtAddress.Text);
                    cmd.Parameters.AddWithValue("@Password", txtPassword.Text);
                    cmd.Parameters.AddWithValue("@DoB", dtpDOB.Value);


                    // Execute the command
                    int rowsAffected = cmd.ExecuteNonQuery();

                    if (rowsAffected > 0)
                    {
                        // Retrieve the last inserted ID
                        cmd.CommandText = "SELECT LAST_INSERT_ID()";
                        int id = Convert.ToInt32(cmd.ExecuteScalar());

                        // Display a message
                        MessageBox.Show("Registered Successfully. Customer ID: " + id.ToString(), "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        // Clear the data
                        ClearData();
                    }
                    else
                    {
                        MessageBox.Show("Registration failed.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    con.Close();
                }
            }
            else
            {
                ClearData();
            }

so what seems to be the problem? what are your thoughts?

ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
  • Is this question in definitely related to C#? Have you confirmed that executing the procedure directly through something like MySQL Workbench doesn't produce the same problem? If you have, what is the exact error message you get in C#? – ProgrammingLlama May 19 '23 at 09:34
  • 1
    Also if it is c# related, there is a lot of code which is not related to the problem (nearly more than half of the lines) and put only a lot of noise to the question – Sir Rufo May 19 '23 at 09:39
  • 1
    Please see e.g. [Creating a procedure in mySql with parameters](https://stackoverflow.com/q/5039324) or the [mysql documention](https://dev.mysql.com/doc/refman/8.0/en/create-procedure.html) for the correct syntax for procedure parameters. Your current procedure header is `CREATE Procedure customer_reg()`. Just as in c#, parameters in mysql are placed inside the `()`. It has (and thus expects) 0 parameters right now. – Solarflare May 19 '23 at 09:48

0 Answers0