There are 3 types of prepositions, akkusativ, dativ and genetiv. Akkusativ is when something is the object in the sentence and is certain prepositions like fuer and durch that always take akkusativ. This means that the following article (der/ein) is the akkusativ form (den/die/das/die or einen/eine/ein/eine). Dativ prepositions are things like nach bis and mit which cause the article to take the dative form (dem/der/dem/den or einem/einer/einem/einen). Some prepositions however can be both akkusativ or dativ depending on the context. These are transitive prepositions e.g. in and an. Transitive prepositions take dativ when there is no movement and akkusativ when there is movement. For example I go in the building 'Ich gehe in das Gebaeude'(there is movement into the building) vs I am in the building 'Ich bin in dem Gebaeude' (no movement).