Small width layout Medium width layout Maximum width layout Small text Medium text Large text
     Search
Downloads Downloads Directory Directory Forums Forums Forge Forge Blogs Blogs        Marketplace Marketplace Careers Program Careers
Community › Forums Register  |  

Affordable ASP.NET Hosting Service
  Need Help?  
Professional technical support for DotNetNuke is available from DotNetNuke Corporation.
 


  Ads  
 


  Sponsors  

Meet Our Sponsors

Red-Gate Software
MaximumASP
SourceGear - Tools for Developers
.: CounterSoft :.
telerik
ExactTarget email software solutions
 


DotNetNuke Forums
 
  Forum  General DotNetN...  Extend It! ( Pr...  Output Parameter
Previous Previous
 
Next Next
New Post 1/14/2008 3:15 AM
User is offline vonPryz
1 posts
10th Ranked


Re: Output Parameter 

 Oliver Ogg wrote
I believe this is because I could explicitly declare that the the CommandType was StoredProcedure.  This meant output parameters behaved correctly.

    SqlParameter[] searchParams = new SqlParameter[4];
    // add some parameters here

 List events = DotNetNuke.Common.Utilities.CBO.FillCollection((IDataReader)(
    SqlHelper.ExecuteReader("", CommandType.StoredProcedure, "Search_Event_Upcoming", searchParams))
    );

eventCount = (int)searchParams[3].Value;




 
This is a bit old thread, but as I fought a lot with the same problem, here are my two cents.

The problem with output parameters is caused by the IDataReader. As you know, it is a one-way reader to data. Stored procedure output parameter values are appended into the end of data stream. This means the values are readable with real values only after IDataReader is closed. CBO.FillCollection() acutally does this, so after filling a collection the output param values do contain appropriate values.

Should you use code like:

// set searchParams parameters here

IDataReader rdr = SqlHelper.ExecuteReader("", CommandType.StoredProcedure, "Search_Event_Upcoming", searchParams);

eventCount = (int)searchParams[3].Value; // this is the output parameter

List events = DotNetNuke.Common.Utilities.CBO.FillCollection<List>(rdr);


... would just give you a null for output parameter value. That is because parameter values are available only after closing the IDataReader - which happens within FillCollection() method.

This behaviour is a bit problematic if you use the DAL model. In order to work with output parameters, you would need to send DB specific method parameter to the class providing the actual implementation of abstract DataProvider. Until I really am missing something, this breaks horribly the whole nice idea of having abstract factory. Consider a control using, say, GridView myGridView:

// Some ascx control file:
protected void Page_Load(){
    // stuff here
    myGridView.DataSource = Controller.SomeMethod(foo, bar);
    myGridView.Bind();

}

// Controller class:
public List<SomeObjectType> SomeMethod(type foo, type bar){
    return CBO.FillCollection<SomeObjectType>(DataProvider.Instance.SomeMethod(foo, bar));
}

 // Abstract dataprovider:
public abstract IDataReader SomeMethod(type foo, type bar);

// Actual implementation:
public override IDataReader SomeMethod(foo, bar){
    return (IDataReader)SqlHelper.ExecuteReader(
    // All the parameters here
    );
}


How would you get access to SqlParameter set as output one? I see no obvious way for such an operation. We could alter the DB interface like this:

 // Abstract dataprovider:
public abstract IDataReader SomeMethod(type foo, type bar, out SqlParameter zof);

// Actual implementation:
public override IDataReader SomeMethod(foo, bar, out SqlParameter zof){
    // Set up zof as SqlParameter that is output value.
    return (IDataReader)SqlHelper.ExecuteReader(
    // All the parameters here
    );
}


Now the controller would get access to output param:

// Controller class:
public List<SomeObjectType> SomeMethod(type foo, type bar){
    SqlParameter zof;
    List<SomeObjectType> myList = CBO.FillCollection<SomeObjectType>(DataProvider.Instance.SomeMethod(foo, bar, out zof));
    // zof.Value can be used here
   
    return myList;
}


... But this approach forces controller class to use DB specific method call as the last parmeter to the DataProvider call is SqlParameter - which is SQL Server specific class, not a generic parameter for any SQL database. Am I missing something here?

-P

 
Previous Previous
 
Next Next
  Forum  General DotNetN...  Extend It! ( Pr...  Output Parameter
 


Forum Policy

These Discussion Forums are dedicated to the discussion of the DotNetNuke Web Application Framework.

For the benefit of the community and to protect the integrity of the project, please observe the following posting guidelines:

1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DotNetNuke.
2. Discussion or promotion of DotNetNuke product releases under a different brand name are strictly prohibited.
3. No Flaming or Trolling.
4. No Profanity, Racism, or Prejudice.
5. Site Moderators have the final word on approving/removing a thread or post or comment.
6. English language posting only, please.

 


Smart-Thinker
DNN Modules for Social Networks for as low as $69 for 6 modules! We also maintain the DotNetNuke Directory - http://DNNDir.com
www.smart-thinker.com
DNN Photo Gallery
Complete Photo Gallery Management!
www.dnnPhotoGallery.com
R2i - Delivering Serious DNN Services & Solutions
Award Winning Design, Skin construction, Custom Modules and Consulting Services for the Enterprise organization. R2i is the DNN:Map module Project Lead and one of the largest DNN service providers with offices in New York City, Virginia and Baltimore.
www.bi4ce.com

DotNetNuke Corporation   Terms Of Use  Privacy Statement
DotNetNuke®, DNN®, and the DotNetNuke logo are trademarks of DotNetNuke Corporation
Hosted by MaximumASP