Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
System.Data.SqlClient.SqlException: 'The parameterized query '(@UserName nvarchar(4000),@Email nvarchar(4000))UPDATE AspNetUse' expects the parameter '@UserName', which was not supplied.'


In the Edit Controller i am getting this error. Can You please find and help me out.

What I have tried:

public    ActionResult Edit(GetUserData getUserdata)
            {
                string query = "UPDATE AspNetUsers SET Email=@Email where UserName=@UserName";
                string DefaultConnection = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
                using (SqlConnection con = new SqlConnection(connectionString))
                {
                    using (SqlCommand cmd = new SqlCommand(query))
                    {
                        cmd.Parameters.AddWithValue("@UserName", getUserdata.UserName);
                        cmd.Parameters.AddWithValue("@Email", getUserdata.Email);
                        cmd.Connection = con;
                        con.Open();
                        cmd.ExecuteNonQuery();
                        con.Close();
                    }
                }
                return Edit(getUserdata);
            }
Posted
Updated 9-Sep-19 19:45pm
v2

1 solution

Read the error message, it's very exact.
The parameterized query '(@UserName nvarchar(4000),@Email nvarchar(4000))UPDATE AspNetUse' expects the parameter '@UserName', which was not supplied.

So that means that this line:
C#
cmd.Parameters.AddWithValue("@UserName", getUserdata.UserName);
is passing a null value, since any other value would not give the error.

So use the debugger, and look at exactly what your getUserData instance contains, and use the stack trace to follow up the call chain to find out why.

Sorry, but we can't do that for you!
 
Share this answer
 
Comments
Member 14566485 10-Sep-19 1:58am    
how to use stack trace for this one
OriginalGriff 10-Sep-19 3:24am    
https://www.google.com/search?q=how+to+use+stack+trace+visual+studio&oq=how+to+use+stack+trace+visual+studio&aqs=chrome..69i57j69i64.1031j0j9&sourceid=chrome&ie=UTF-8
Member 14566485 10-Sep-19 9:14am    
can u please send me your mail ID I will send my source code to you pls do that for me.
OriginalGriff 10-Sep-19 9:29am    
No - I don't have your data, I have no idea how to use it, and I'd spend far, far too much time working all that out.

You wrote the software, you know what it's supposed to do, and how it's supposed to work - I don't even know how to make the app reach that method, much less what it expects to have passed to it when it gets there!

Come on - testing and debugging is the major part of your time in development: and getting used to how the debugger works and what it can do to make your life easier (hint: a lot, lot easier) is time invested, not wasted. Wasted time is waiting for other people to do it for you when they have no real information to work with ... so give it a go! It's not complicated, and it's well and truly worth it!
Member 14566485 10-Sep-19 9:39am    
ok

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900