The two ways are fundamentally different because if the shares in a target company are purchased, all its assets, liabilities and obligations are also acquired (even those the buyer does not know about). However if on the other hand just the assets are purchased, only the identified assets (and any liabilities which the buyer agrees to take) are acquired.
On a share purchase, shares in the target company are transferred to the buyer by means of a stock transfer form. Where just assets are changing hands, those assets need to be identified and transferred to the buyer by specific forms of transfer and contract.
The other key commercial difference between the two types of transactions is in the nature of what the buyer acquires. On a share purchase, it acquires a company which owns a business and which is running that business with a host of ongoing contracts, as a going concern. An asset purchase will not automatically transfer contracts or existing trading arrangements to the buyer - the buyer will just get assets that it can use in its business.