LLBLGen - How to execute an IRetrievalQuery

341 views Asked by At

I am trying to execute an IRetrievalQuery using the execute() method but I am getting the error "No connection is present. Cannot execute command." The documentation tells that I need to open a connection but I am not sure how. What should I do to execute my query ? Any ideas ? I am using LLBLGen version 2.6.

Code:

IRetrievalQuery query = RetrievalProcedures.GetLlmBudgetGetDepTotalCancelledCallAsQuery(month, BudgetUtils.CurrentTerm(), department);

DataTable data = new DataTable();
data.Load(query.Execute(CommandBehavior.CloseConnection)); // execute fails 
1

There are 1 answers

1
Cemre Mengü On

I asked it on LLBLGEN form and this is the answer I got. I basically needed something like below:

using( DataAccessAdapter adapter = new DataAccessAdapter() )
{
    IDataReader reader = adapter.FetchDataReader( 
        RetrievalProcedures.GetCustOrdersOrdersCallAsQuery( "CHOPS" ), 
        CommandBehavior.CloseConnection );
    while( reader.Read() )
    {
        Console.WriteLine( "Row: {0} | {1} | {2} | {3} |", reader.GetValue( 0 ), 
            reader.GetValue( 1 ), reader.GetValue( 2 ), reader.GetValue( 3 ) );
    }
    // close reader, will also close connection
    reader.Close();
}

The IDataReader instance in the example can also be used to load the data into a DataTable using its Load method.