Dynamically assigning datasource for a query in AOT

can any one tell me how to assign datasource to a query present in AoT 
through code. I am able to add a new query to AOT dynamically and delete it. 
But not able to assign a datasource and range to that ...