Reputation: 621
I'm trying to make a function to password reset. I have a database with 3 columns: Username, Password, Email. I want to update the password for a specific email address. I used the following code:
try
{
SqlConnection connection = new SqlConnection();
connection.ConnectionString = "Server=WIN2CNG9\\SQLEXPRESS;Database=OOPII_Project;Trusted_Connection=true";
SqlCommand cmd = new SqlCommand();
cmd.Connection = connection;
cmd.CommandText = "UPDATE Users SET Password = @pass WHERE Email = @email";
cmd.Parameters.AddWithValue("@pass", md5Kod);
cmd.Parameters.AddWithValue("@email", Email);
connection.Open();
cmd.ExecuteNonQuery();
MessageBox.Show("Ok");
connection.Close();
this.Close();
}
But nothing happens in my database. I tried also to make a simple insert command:
cmd.CommandText = "INSERT INTO Users (Username, Password, Email) VALUES ('a', 'b', 'c')";
Here the same result, nothing happens.
Where is my mistake?
Thank you!
Upvotes: 0
Views: 401
Reputation: 53958
This line
cmd.Parameters.AddWithValue("@fn", Email);
should change to this
cmd.Parameters.AddWithValue("@email", Email);
You have two parameters, @pass
and @email
. While for the first one you pass a value, for the second you don't.
Upvotes: 1