I looked in the forum a lot and researched for my problem but I couldn`t find something that helped me.
I have tried a lot of suggestions from here.
I have a site and 3 sign up pages. every page have some information, validators are already set up and I built an SQL Server (Microsoft visual studio community 2015). Here is the code of the first sign up page:
The problem was that Table is a reserved word, I just had to write [Table] instead of Table in the sqlCommand
Any help will be estimated.
You need to add quotes around your parameters when assigning a value:
sqlCommand.Parameters["@email"].Value = email; sqlCommand.Parameters["@username"].Value = userName;
The reason why you need quotes is because in your case
@ symbol in C# in answers to What's the use/meaning of the @ character in variable names in C#?
For recommendation why to use
Add in favor of
AddWithValue please refer to this article.
EDIT: It seems the issue is different. In your code you assign
string email = null, userName = null;
Then nowhere in the code you change these values, i.e. they still remain
null. Then when you get to this line:
if (email != null && userName != null)
your values are still
null, and the logic inside
if statement is never executed. Fix this part of the code first, and then my initial answer will become helpful as well.
UPDATE 2 SQL Parameters collection does not contain the parameters, so it needs to be performed using
sqlCommand.Parameters.Add("@email", SqlDbType.VarChar, 50).Value = email; sqlCommand.Parameters.Add("@userName", SqlDbType.VarChar, 12).Value = userName;