Assuming God is omni-everything, when He created Adam and Eve he knew they would eat of the fruit. In fact you could go so far as to say he wanted them to eat the fruit in that particular way.
I mean if you put a big red button on a wall with a notice saying 'do not press' next to it, how many peolpe are going to press it? Lots, because its our nature to enquire (which God created incidently).
Assuming it happened as in the Bible, God set the whole situation up, why i have no idea, but then the stock answer gets wheeled out - 'He works in myterious ways'