Databind to a TypedView filled from stored procedure

Posts   
 
    
raist
User
Posts: 114
Joined: 19-Apr-2010
# Posted on: 30-May-2011 21:05:48   

Hi, We have a parameter-based stored procedure that returns a resultset we have mapped to a TypedView. Therefore we can fill the TypedView as in the documentation...

CustomersOnCountryTypedView customersTv = new CustomersOnCountryTypedView()
// Fill the TypedView with a class method that internally calls the stored procedure
customersTv.Fill(null, "USA");

... but we'd like to view it in a web grid. How can we bind that TypedView to a LLBLGenProDataSource (or LLBLGenProDataSource2)?

The code from the fill method is something like

public bool Fill(ITransaction transactionToUse, System.String countryID)
        {
            bool toReturn;
            using(IRetrievalQuery query = RetrievalProcedures.GetQueryForCustomersOnCountryTypedView(countryID))
            {
                toReturn = new TypedListDAO().GetMultiAsDataTable(GetFields(), this, query, transactionToUse);
            }
            return toReturn;
        }

We tried some explicit cast with ITypedView, but it didn't work.

It should be really simple, but we don't get it right. confused

TIA

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 31-May-2011 07:18:21   

You will have to use LLBLGenProDataSource and intercept activity. So, implement the PerformSelect event handler and there you can fill your view and map it to the data source.

If you need further assistance on this please let us know.

David Elizondo | LLBLGen Support Team
raist
User
Posts: 114
Joined: 19-Apr-2010
# Posted on: 31-May-2011 12:21:24   

Thanks for your help Daelmo. We tried before to implement the event handler.

The problem is that CustomersOnCountryTypedView doesn't implement ITypedView. So, whatever we do, we get a cast error (we cannot pass the "USA" parameter to e.ContainedTypedView.Fill(...)

We've tried (again) to implement the event handler passing the SP resultset directly to the GridView. No luck so far:

 protected void customersDS_PerformSelect(object sender, PerformSelectEventArgs e)
    {
        DataTable dc = RetrievalProcedures.SpCustomersOnCountry("USA");
        theGrid.DataSource = dc;                    
    }

raist
User
Posts: 114
Joined: 19-Apr-2010
# Posted on: 31-May-2011 12:52:46   

Solved, but a little bit aesthetic disappointed - No llblgenprodatasource databinding, therefore, no TypedView used (only the SP call)

protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            DataTable dc = RetrievalProcedures.SpCustomersOnCountry("USA");
            theGrid.DataSource = dc;
            theGrid.DataBind();
        }
    }

Is there a better way?

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 31-May-2011 13:55:30   

TypedViews made from SP's resultSets don't implement ITYedView indeed.

You can implement the interface if you want. The trick is that most SPs take parameters, while ITypedView has a fill method with no parameters.

So you will need to have properties to set these parameters, or maybe in a CTor and then implement the ITypedView.Fill() method, which passes these parameters to the already existing Fill() mehod with parameters.

Also you will need to implement count and GetDbCount().

But I don't see a point for all this, unless you want to use LLBLGenProDataSource, for design time databinding.