CodeSmith Community
Your Code. Your Way. Faster!

Custom Stored Procedure GridView Help Needed

Latest post 11-17-2006 1:52 AM by swin. 8 replies.
  • 11-16-2006 12:51 AM

    • cto7182
    • Not Ranked
    • Joined on 11-16-2006
    • Posts 4
    • Points 170

    Custom Stored Procedure GridView Help Needed

    First let me say that this CodeSmith and .NetTiers are great products, but I need a bit of help with them.

    We are trying to create a stored procedure to use with an entitygridview on an aspx page in our website.  What we have tried is not working, we have no idea why and were hoping that someone in the community might be able to help.

    The custom stored procedure is as follows (using a shortened stored procedure for example's sake):

    ALTER PROCEDURE dbo._Job_JobInfo
    @JobID
    int
    AS
    SELECT
    [JobID],
    [JobName]
    FROM
    Job
    WHERE
    [JobID] = @JobID
    RETURN

    We are able to build the soultion without any errors, but I don't know where to the _Job_JobInfo information is being generated in the solution or how I should call it in the aspx page.

    I was under the impression that I could set up the JobDataSource as follows and it work.

    <data:JobDataSource ID="Jobdata" runat="server" SelectMethod="JobInfo">
    <Parameters>
    <asp:QueryStringParameter Name="JobID" QueryStringField="JobID" Type="int32" />
    </Parameters>
    </data:JobDataSource>

    Of course it doesn't "just work".  I am getting "Error 22 Validation (ASP.Net): The values permitted for this attribute do not include 'JobInfo' ".

    I have included all of the using statements I can think of in the code behind hoping that would help, but that was a waste of time.

    So, does anyone have any idea what I am doing wrong and the best way to correct it?

    ~Clayton

    • Post Points: 65
  • 11-16-2006 2:00 AM In reply to

    • swin
    • Top 10 Contributor
    • Joined on 06-14-2006
    • London, UK
    • Posts 924
    • Points 34,750

    Re: Custom Stored Procedure GridView Help Needed

    Clayton,

    I think the strongly typed data sources only support the auto generated methods and not custom stored procs - hence the error message.

    Is your csp returning a TList of entities or a dataset/reader??

    Your alternatives are the EntityDataSource or if your csp is returning a dataset see my tip (http://community.codesmithtools.com/forums/thread/18699.aspx) for a quick and easy way to link the csp and the EntityGridView using an ObjectDataSource.

    HTH

    swin

    ------------------------------------------------- Member of the .NetTiers team -------------------------------------------------
    • Post Points: 5
  • 11-16-2006 8:50 AM In reply to

    • jcteague
    • Top 10 Contributor
    • Joined on 03-10-2005
    • Austin, Tx
    • Posts 442
    • Points 10,925

    Re: Custom Stored Procedure GridView Help Needed

    Clayton is correct on both counts.  Custom procedure only return an entity object if all properties are returned.  Othersiwe a datagrid or reader is returned based on the generation options.

    On 11/16/06, cto7182 <bounce-cto7182@codesmithsupport.com> wrote:

    First let me say that this CodeSmith and .NetTiers are great products, but I need a bit of help with them.

    We are trying to create a stored procedure to use with an entitygridview on an aspx page in our website.  What we have tried is not working, we have no idea why and were hoping that someone in the community might be able to help.

    The custom stored procedure is as follows (using a shortened stored procedure for example's sake):

    ALTER PROCEDURE

    dbo._Job_JobInfo
    @JobID
    int
    AS
    SELECT
    [JobID],
    [JobName]
    FROM
    Job
    WHERE
    [JobID] = @JobID
    RETURN

    We are able to build the soultion without any errors, but I don't know where to the _Job_JobInfo information is being generated in the solution or how I should call it in the aspx page.

    I was under the impression that I could set up the JobDataSource as follows and it work.

    <data:JobDataSource ID="Jobdata" runat="server" SelectMethod="JobInfo">
    <Parameters>
    <asp:QueryStringParameter Name="JobID" QueryStringField="JobID" Type="int32" />
    </ Parameters>
    </data:JobDataSource >

    Of course it doesn't "just work".  I am getting "Error 22 Validation (ASP.Net): The values permitted for this attribute do not include 'JobInfo' ".

    I have included all of the using statements I can think of in the code behind hoping that would help, but that was a waste of time.

    So, does anyone have any idea what I am doing wrong and the best way to correct it?

    ~Clayton





    Thanks, John Teague ------------------------------ Member of the .NetTiers team http://www.nettiers.com ------------------------------

    • Post Points: 35
  • 11-16-2006 11:55 AM In reply to

    • cto7182
    • Not Ranked
    • Joined on 11-16-2006
    • Posts 4
    • Points 170

    Re: Custom Stored Procedure GridView Help Needed

    Thanks to you both swin and John for your replies.

     Swin, I have also tried what you suggested (I came across the post you mentioned in some of my eariler searches).  When I try using the object data source I receive the "No parameterless constructor defined for this object" message.

    The code for my object data source is as follows:
    <asp:ObjectDataSource ID="ods" runat="server" SelectMethod="JobInfo" TypeName="Root.Data.SqlClient.SqlJobProvider" >
    <SelectParameters>
    <asp:QueryStringParameter DefaultValue="9" Name="jobID" QueryStringField="JobID" Type="Int32" />
    </SelectParameters>
    </asp:ObjectDataSource>

    I assumed that the paramater section would be where the paramaters should be passed in, and by setting the "DefaultValue" would force a value in the paramater regardless of whether or not the query string was correct (I have tried with both correct and incorrect query strings).  I have tested the original custom stored procedure, with the value of 9, and it works just fine.

    Does anyone have any other ideas that I can try?

    ~Clayton

    • Post Points: 35
  • 11-16-2006 12:33 PM In reply to

    • jcteague
    • Top 10 Contributor
    • Joined on 03-10-2005
    • Austin, Tx
    • Posts 442
    • Points 10,925

    Re: Custom Stored Procedure GridView Help Needed

    The ObjectDataSource does not like netTiers very much.  It expects a specific design, which we do not follow.
     
    The easiest thing to do is to create a new class that wraps your netTiers call.
     
    public class ODSWrapper{
     
      public DataSet GetJobInfo(int jobID){
        return DataRepostitory.JobProvider.JobInfo(jobID)
      }
     
    }
     
    There are some old post about using ObjectDataSource that will help.  Searching on ObjectDataSource should help.
     


     
    On 11/16/06, cto7182 <bounce-cto7182@codesmithsupport.com> wrote:

    Thanks to you both swin and John for your replies.

     Swin, I have also tried what you suggested (I came across the post you mentioned in some of my eariler searches).  When I try using the object data source I receive the "No parameterless constructor defined for this object" message.

    The code for my object data source is as follows:
    <asp:ObjectDataSource ID="ods" runat ="server" SelectMethod="JobInfo" TypeName ="Root.Data.SqlClient.SqlJobProvider" >
    <SelectParameters >
    <asp: QueryStringParameter DefaultValue="9" Name="jobID" QueryStringField="JobID" Type="Int32" />
    </SelectParameters>
    </ asp:ObjectDataSource>

    I assumed that the paramater section would be where the paramaters should be passed in, and by setting the "DefaultValue" would force a value in the paramater regardless of whether or not the query string was correct (I have tried with both correct and incorrect query strings).  I have tested the original custom stored procedure, with the value of 9, and it works just fine.

    Does anyone have any other ideas that I can try?

    ~Clayton





    Thanks, John Teague ------------------------------ Member of the .NetTiers team http://www.nettiers.com ------------------------------

    • Post Points: 35
  • 11-16-2006 2:15 PM In reply to

    • cto7182
    • Not Ranked
    • Joined on 11-16-2006
    • Posts 4
    • Points 170

    Re: Custom Stored Procedure GridView Help Needed

    John, I feel like a bit of a dunce for having to ask, but what do I do once I have created the wrapper for the nettiers call?

    Am I making this more difficult than it needs to be?  All I want to do in the long run, is to use nettiers with a custom stored procedure that returns data from two tables and displays it on a web page (so someone on the web can see it, not edit, update or delete). 

    Thanks again for all the help, and I'm sorry to be such a bother,

    ~Clayton

    • Post Points: 35
  • 11-16-2006 3:10 PM In reply to

    • jcteague
    • Top 10 Contributor
    • Joined on 03-10-2005
    • Austin, Tx
    • Posts 442
    • Points 10,925

    Re: Custom Stored Procedure GridView Help Needed

    No Problem,
     
    Create the ODS with the typename being the name of the wrapper class and the SelectMethod the name of the method that wraps the netTiers method.

    <

    asp:ObjectDataSource TypeName ="TypeNameOfWrapper" SelectMethod="NameOfWrapperMethod" ID="ObjectDataSource1" runat="server">

    </

    asp:ObjectDataSource>
    The one thing I forgot when I looked at the old forum was the [DataObject] attribute applied to the class name 
     
    [DataObject]
    public class ODSWrapper{...}
     
    HTH
     
    On 11/16/06, cto7182 <bounce-cto7182@codesmithsupport.com > wrote:

    John, I feel like a bit of a dunce for having to ask, but what do I do once I have created the wrapper for the nettiers call?

    Am I making this more difficult than it needs to be?  All I want to do in the long run, is to use nettiers with a custom stored procedure that returns data from two tables and displays it on a web page (so someone on the web can see it, not edit, update or delete). 

    Thanks again for all the help, and I'm sorry to be such a bother,

    ~Clayton





    Thanks, John Teague ------------------------------ Member of the .NetTiers team http://www.nettiers.com ------------------------------

    • Post Points: 35
  • 11-16-2006 6:09 PM In reply to

    • cto7182
    • Not Ranked
    • Joined on 11-16-2006
    • Posts 4
    • Points 170

    Re: Custom Stored Procedure GridView Help Needed

    Reply |Contact |Answer

    Okay, well thanks to your help I was able to get it to work.

    When you were talking about classes, I did not realize that you meant I should create a new class in the App_Code.

    To anyone who might have this problem later on, I had to right click on the App_Code section of my web site, click 'Add New Item', select 'Class', name it appropratly (in this case ODSWrapper.cs), click 'Add', and then add the following code to the newly created class (where Domain is the RootNameSpace that is being used in my program).

    using Domain.Data;
    [System.ComponentModel.
    DataObject]
    public class ODSWrapper
    {
    public DataSet ViewJobInfo(int jobID)
    {
    return DataRepository.JobProvider.JobInfo(jobID);
    }
    }

    The DataObject that John mentioned required that you use the System.Component system information.  Of course this could have been shortened by a using statement of System.ComponentModel. 

    The code added to the aspx page is as follows.

    <asp:ObjectDataSource ID="ObjectDataSource3" runat="server" SelectMethod="ViewJobInfo" TypeName="ODSWrapper">
    <SelectParameters>
    <asp:QueryStringParameter Name="jobID" QueryStringField="JobID" Type="Int32" />
    </SelectParameters>
    </asp:ObjectDataSource>

    <asp:DetailsView ID="DetailsView1" runat="server" DataSourceID="ObjectDataSource3" AutoGenerateRows="False">
    <Fields>
    <asp:BoundField DataField="JobName" HeaderText="Job Name" />
    </Fields>
    </asp:DetailsView>

    Of course this was used with a query string and that can be modified to fit whatever type of paramater you are needing to return.

    As a side note, I was able to modify the stored procedure later adding more fields and joining tables, and it still worked just fine.  I was originally worried that it would not work since it had been built by CodeSmith (I did have the stored procedures added into the database).

    Anyway, thanks again for the help, and thanks to everyone who built this product it is really a great tool (I just needed a little help understanding everything).

    ~Clayton

    • Post Points: 35
  • 11-17-2006 1:52 AM In reply to

    • swin
    • Top 10 Contributor
    • Joined on 06-14-2006
    • London, UK
    • Posts 924
    • Points 34,750

    Re: Custom Stored Procedure GridView Help Needed

    Hi Clayton,

    Just to let you know that if you generate the service layer your csp method will be accessible through the xxxService for your entity.  The service classes have a parameterless constructor which means you can use it directly with the ODS without hvaing to create your own wrapper.  This is what I did and I didn't have to hand code anything.

    HTH

    swin

    ------------------------------------------------- Member of the .NetTiers team -------------------------------------------------
    • Post Points: 5
Page 1 of 1 (9 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems