The taxonomic superorder of Dinosauria contains two specific orders: Saurischia and Ornithischia. It is unlikely that all of the large number of species classified under these two orders could swim, but it is far more unlikely that none of them could. The species of reptiles that are taxonomically classified as dinosaurs have been shown to be predominantly terrestrial. They lived and thrived on land masses that formed continents that few people today would recognize in comparison to today's geography. They shared their world with other reptiles such as the pliosaurs that dominated the seas, but these other reptiles, while sharing the taxonomic class Reptilia, were not dinosaurs.
These two taxonomic orders are defined based on the pelvic bone structure of the multitude of species within them. Saurischian species are described as being "lizard-hipped" while Ornithischian species are called "bird-hipped". All species grouped under the taxonomic order Ornithischia have a pubis bone that points downward and towards the back or tail of the animal. In comparison, those in the order Saurischia have a pubis bone that points down and forward. Neither pelvic bone structure would deny an animal the ability to swim.
While most of us tend to think of dinosaurs as enormous animals, only a relatively small percentage of dinosaur species were actually that gigantic. Most dinosaur species were of a comparatively moderate size comparable to today's larger mammals, or even smaller. They also existed on our planet as a taxonomic superorder for an extremely long time, approximately 160 million years. During this time, various dinosaur species evolved, dominated and then became extinct.
The ability to swim for a specific dinosaur species would be dependent on the environment it lived in and the instinctive behaviors it had evolved to enable it to survive. Dinosaur species living in arid environments far from any significant bodies of water would have no reason to develop the ability to swim. Those living in swamplands, river basins and floodplains would have evolved or learned swimming techniques to enhance their ability to survive in such environments, or moved to drier lands, or become extinct. We should realize that many dinosaur species did become extinct during those 160 million years, prior to the major extinction event that removed them from planetary dominance.
What we don't know about dinosaurs exceeds what we do by a very large amount. Structural hints in prehistoric riverbeds have been assessed as dinosaur tracks that offer indications that dinosaur body mass aided floating and therefore potentially swimming. Computer modeling of dinosaur body shapes and masses, as determined from fossilized skeletal remains, compared to currently extant mammal equivalents have also shown the potential for dinosaur species to swim.
It is virtually certain that some species of dinosaur were unable to swim, those living in arid environments where the need would never arise. Those living in environments where the need would occur, would have predominantly had the ability.