Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old July 5th, 2006, 09:07 AM
Registered User
 
Join Date: Jul 2006
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default output parameters with the objectdatasource

Hi,

I have an objectdatasource with a selectmethod. that method then calls a stored procedure and creates a datatable that gets sent back to the objectdatasource. My problem is that even though I have a output paramater on the objectdatasource it doesn't receive a value.

Here is the code, any healp is appreciated.

Stored Proc
Code:
ALTER PROCEDURE [dbo].[GetPagedWines]
    @PageIndex INT, 
    @NumRows INT,
    @TotalCount INT OUTPUT
AS

BEGIN 
 
SELECT @TotalCount = 150 /*(SELECT COUNT(*) FROM Wine AS TotalCount)*/

DECLARE @StartRowIndex INT;
SET @StartRowIndex = (@PageIndex * @NumRows) + 1;

WITH ListEntries AS ( 
SELECT ROW_NUMBER() OVER (ORDER BY WineID_PK ASC)AS Row, * FROM Wine)

SELECT *, @TotalCount AS TotalCount
FROM ListEntries 
WHERE Row between @StartRowIndex and @StartRowIndex+@NumRows

RETURN
END
objectdatasource
Code:
<asp:ObjectDataSource ID="odsWineList" runat="server" TypeName="BLL.WineFunctions.WinesBLL" SelectMethod="GetPagedWinesBLL">
    <SelectParameters>
        <asp:Parameter Name="PageIndex" DefaultValue="0" />
        <asp:Parameter Name="numRows" DefaultValue="10" />
        <asp:Parameter Name="TotalCount" Direction="Output" DefaultValue="0"/>
</SelectParameters>
</asp:ObjectDataSource>
Code:
 Public Function GetPagedWinesBLL(ByVal numRows As Integer, ByVal PageIndex As Integer, ByVal TotalCount As Integer) As Wines.WinesDataTable
            Return Adapter.GetAllWinesPaged(PageIndex, (numRows - 1), TotalCount)
         End Function


  #2 (permalink)  
Old May 18th, 2007, 01:19 AM
Registered User
 
Join Date: Feb 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to atifahmedsiddiqui
Default

yes.. i do have the same problem... but i m using c#,
so my function is..

public DataTable GetPages(int startRowIndex, int maximumRows, out int? TotalRecords)
{
    return Adapter.GetPages(startRowIndex, maximumRows, out TotalRecords)
}

plz help us Gurus :)

  #3 (permalink)  
Old August 25th, 2008, 12:41 PM
Registered User
 
Join Date: Aug 2008
Location: Jacksonville, FL, USA.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Team:
this should clear the air for you:

- ASPX -
<asp:GridView ID="grvSearchResults" runat="server">
</asp:GridView>
<asp:ObjectDataSource ID="obdsSearchResults" SelectMethod="SearchLegalEntity"
    SelectCountMethod="SearchLegalEntityCount"
    runat="server"
    TypeName="LEMS.Helper.LESearch">
 </asp:ObjectDataSource>

 - Code Behind -

public void GetSearchResults()
    {
        ControlParameter param = new ControlParameter("searchCriteria", TypeCode.Object, this.ID, "SearchCriteria");
        obdsSearchResults.SelectParameters.Add(param);
        Parameter parOut = new Parameter("statusCodeList", TypeCode.Object);
        parOut.Direction = ParameterDirection.Output;
        obdsSearchResults.SelectParameters.Add(parOut);
        grvSearchResults.DataSource = obdsSearchResults;
        obdsSearchResults.Selected +=new ObjectDataSourceStatusEventHandler(obdsSearchResul ts_Selected);
        grvSearchResults.DataBind();
    }
    protected void obdsSearchResults_Selected(object sender, ObjectDataSourceStatusEventArgs e)
    {
        if (e.OutputParameters["statusCodeList"] == null)
            return;
        StatusCodeList = (IList<LEMS.Common.Proxy.WBStatus>)e.OutputParamet ers["statusCodeList"];
    }

So in other words the idea is to add a new event handler which would run right after the data is fetched and before the DataBind() method has finished running and extract your output parameter values from the ObjectDataSourceStatusEventArgs object which conveniently has OutputParameters property. Feel free to typecast the object to whichever custom class you want as shown above. StatusCodeList in code above is a public property of the same type as the typecast. The DridView definition in ASPX code does not use DataSourceID property because I want to control when and how I envoke DataBind, which as you can see is taken care of in my custom method on the code behind.

Enjoy! If it doesn't help, let me know. See, sometimes it does pay off asking Gurus for help! :)
:)


Similar Threads
Thread Thread Starter Forum Replies Last Post
Output Parameters: I can't be this stupid... raysot BOOK: Professional SQL Server 2005 Integration Services ISBN: 0-7645-8435-9 13 May 20th, 2010 07:28 PM
Chapter 6 "Using SQL Output Parameters..." burkecrosby BOOK: Professional SQL Server 2005 Integration Services ISBN: 0-7645-8435-9 22 February 10th, 2010 05:33 PM
Output Parameters Bob Bedell SQL Server 2000 2 March 25th, 2006 06:32 AM
OUTPUT Parameters saulodet ADO.NET 0 May 14th, 2004 10:02 AM
SQL output parameters ohiggs SQL Server 2000 4 February 9th, 2004 10:09 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.