The simple reason is that the Vietnamese were fighting for their independence and were prepared to fight forever for that ideal.
The US government saw the Vietnamese as puppets of Moscow who were fighting for communism, and thought they could be persuaded to give up if they were bombed enough.
The Americans, under Defence Secretary McNamara- an ex-General Motors CEO- took a 'rational' approach and saw the war as a 'cost-benefit analysis': if the cost to the Vietnamese outweights the benefits they receive from victory, then they will give up. Of course, the Vietnamese were fighting fr an emotional idea and Americans of all people should have understood this.
Another problem was that America created the puppet South Vietnamese government, which never really had any credibility to the Vietnamese, because it was self-serving and corrupt. It was hard to find people who would fight for it and feel committed to it. But the US government did not understand this and saw it's puppet government as equal in legitimacy to the government of Ho Chi Minh, whoch had fought for independence since the early 1940s.
A final factor was that for the US the cost/benefit analysis did not make sense. The benefit of a pro-US south Vietnam was not worth the deaths and the incredible expense of this war. The US public could not see the value in taxes and having their sons killed. By the time the US pulled out of the war in the early 1970s, their side was in fact doing very well militarily, but South Vietnam was wrecked by warfare and by the corruption that occurs when lots of money is poured into a poor third world nation.
Many of these lessons were forgotten before Iraq.