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  |  

AppTheory specializes in solutions based on the DotNetNuke platform and has 2 employees on the DotNetNuke Core Team.
  Need Help?  
Professional technical support for DotNetNuke is available from DotNetNuke Corporation.
 


  Ads  
 


  Sponsors  

Meet Our Sponsors

DataSprings - Great Ideas. Always Flowing.
R2integrated - formerly bi4ce
Jango Studios - Skins, Modules and Hosting for DotNetNuke
eUKhost.com is commited to offer exceptional UK Windows Web Hosting solutions with quality 24x7 technical support.Our plans support ASP.Net, ASP, ASP.NET Ajax extensions, XML, MSSQL, MySQL, PHP,DNN, multiple domains and Shared SSL as standard.
SmarterTools
The Official Microsoft ASP.NET Website
 


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.

 


ADefWebserver.com
DotNetNuke® Module Development Help Website
ADefWebserver.com
Get Smarter Mail, SmarterStats, SmarterTickets
Windows mail server, web log analytics, and customer service management software - Free Editions Available!
www.smartertools.com
Venexus, Inc.
Need custom a custom DotNetNuke module? From module planning to deployment, including training and support, Venexus developers deliver end-to-end web solutions on time and on budget.
www.venexus.com

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