[Solved] Procedure or function ‘InsertUser’ expects parameter ‘@Username’, which was not supplied [closed]


Did you see inside the executenonquery method of the connection class this line?

cmd = new SqlCommand(qry, conn);

This creates a new command, one without any parameters defined. Of course it fails.

The fastest way to fix your code is to change the method executenonquery to receive a already built command or create an overload for it

public void nonquery(SqlCommand cmd)
{
        conn.Open();
        cmd.Connection = conn;
        cmd.ExecuteNonQuery();
        conn.Close();

}

and pass the command that you build in the insert method of the master class

public class master
{
    connection conn = new connection();

    SqlCommand cmd = null;
    public void insert(string username, string password)
    {
        SqlCommand cmd = new SqlCommand("InsertUser");
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.Add("@Username", SqlDbType.VarChar).Value =username;
        cmd.Parameters.Add("@Password", SqlDbType.VarChar).Value =password;
        conn.nonquery(cmd);

    }
}

2

solved Procedure or function ‘InsertUser’ expects parameter ‘@Username’, which was not supplied [closed]