When you add the add to cart button to the page, select the option to lookup item from a recordset.
On the bindings tab, this will set the ID column to use the ID column from the recordset selected.
when this is added to the page, it will create a hidden form element, the hidden form element will have the value set to use the id column from the recordset, this will pass the correct item ID to the add to cart behavior when selected.
If your having trouble getting this to work, please compress you page to a zip archive and attach the zip file to your message so I can see the code to have an idea what may be wrong.