0

I have a register page that saves the data to a database the only problem is when I click the register button I am getting an error which im not too sure how to solve, please see below.

1 Answer 1

8

Your declaring param[] to have 6 elements, but you're only using 5. The last one is null so you're getting the error on the last iteration of your for loop where you add the elements to the SqlParameterCollection.

It would be much cleaner/easier to do the following rather than declaring an array, filling the array, and then trying to copy the array:

cmd.Parameters.AddWithValue("@Name", name);
cmd.Parameters.AddWithValue("@Gender", gender);
cmd.Parameters.AddWithValue("@Age", age);
cmd.Parameters.AddWithValue("@Address", address);
cmd.Parameters.AddWithValue("@Email", email); 
Sign up to request clarification or add additional context in comments.

1 Comment

works fine that thanks but now come across another error - Insert Error:Cannot open database "SJDatabase" requested by the login. The login failed. Login failed for user

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.