This is a migrated thread and some comments may be shown as answers.

[Solved] Get Value from Grid for Stored Procedure

6 Answers 312 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Stefan
Top achievements
Rank 2
Stefan asked on 16 Apr 2013, 09:01 PM
Hi,

I have a grid doing an inline update to a stored procedure.  But I do not know how to get the value of the grid column passed as a parmater to the stored procedure using VS12 VB aspx.   Here is partial code.

           <telerik:RadGrid ID="dgPlans" GridLines="None" runat="server" AllowAutomaticDeletes="True"
              AllowAutomaticInserts="True" AllowAutomaticUpdates="True" AllowPaging="True"
              AutoGenerateColumns="False" CellSpacing="0" Width="716px" DataSourceID="sqlPlans"  

        <telerik:GridDropDownColumn DataField="PlanId" DataSourceID="sqlGetPlans"
            HeaderText="Plan" ListTextField="ippPlan" ListValueField="PlanId"
            UniqueName="ippPlanId" ColumnEditorID="GridDropDownColumnEditor1">
        </telerik:GridDropDownColumn>
    

            UpdateCommand="sp_Update_Plan" UpdateCommandType="StoredProcedure"

            <UpdateParameters>
                <asp:Parameter Name="EffectiveDate" Type="Datetime"></asp:Parameter>
                <asp:Parameter Name="ExpirationDate" Type="Datetime"></asp:Parameter>
                <asp:Parameter Name="Split" Type="Decimal"></asp:Parameter>
                <asp:Parameter Name="Level" Type="String"></asp:Parameter>
                <asp:Parameter Name="PlanId" Type="Int32"></asp:Parameter>
            </UpdateParameters>

Like I said the stored procedure name on my SQL box is sp_Update_Plan and it takes several params.  But what is used as the @ piece of the parameter? What part of the radgrid become the @piece to pass to my SP? The uniquename? The Datafield has to match the @parameter?

All the examples I have seen just have the SQL statement in the updatecommand I need to use as stored procedure.

thanks,

 


 

6 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 17 Apr 2013, 03:46 AM
Hi,

Please check this Code Library which shows an example to Update/Insert/Delete with stored procedures.
Update/Insert/Delete with stored procedures and SqlDataSource control

Thanks,
Princy.
0
Stefan
Top achievements
Rank 2
answered on 18 Apr 2013, 02:11 PM
This is exactly my problem.  And I have matched the names up and I still can not do a simple delete with one parameter.  I want to try how the other user fixed this issue with changing the SelectCommanType to "text" you asked him to upload a working sample and he did but I can not find it in the code library. Can you point on the sample where he has fixed this issue.

thanks.
0
Stefan
Top achievements
Rank 2
answered on 19 Apr 2013, 01:48 PM
*Bump.

Can I get a zip file or link to the project.  I am still unable to pass sql parmaters vi a datasource from a grid.  All the names are matching is there something else?

Thanks
0
Maria Ilieva
Telerik team
answered on 23 Apr 2013, 08:53 AM
Hi Stefan,

You could use the link below:
http://www.telerik.com/community/code-library/aspnet-ajax/grid/automatic-updates-with-different-parameter-names.aspx

Regards,
Maria Ilieva
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Stefan
Top achievements
Rank 2
answered on 23 Apr 2013, 04:01 PM
Thanks,  I have the update and delete working with parameters but the insert is failing saying insert_stored procedure has to many paramaters.  Is its because I have the key in the grid? I don't need the key on an update cause it is generated when the record is created?  It is still trying to pass it as a parameter because it is in my grid but not in my in Insert parameters code block? Here is my code:

    <Columns>
        <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn">
            <ItemStyle CssClass="MyImageButton"></ItemStyle>
        </telerik:GridEditCommandColumn>

        <telerik:GridBoundColumn DataField="ippPlanAssignID" DataType="System.Int32" FilterControlAltText="Filter ippPlanAssignID column" HeaderText="Plan Assign ID" ReadOnly="True" SortExpression="ippPlanAssignID" UniqueName="ippPlanAssignID" Visible="false" >
        </telerik:GridBoundColumn>

        <telerik:GridBoundColumn DataField="EmplID" DataType="System.Int32" FilterControlAltText="Filter EmplID column" HeaderText="Emp. ID:" ReadOnly="False" SortExpression="EmplID" UniqueName="EmplID" Visible ="false">
        </telerik:GridBoundColumn>

        <telerik:GridDropDownColumn DataField="ippPlanID" DataSourceID="sqlGetPlans"
            HeaderText="Plan Description" ListTextField="ippPlanDesc" ListValueField="ippPlanID"
            UniqueName="PlanDesc" ReadOnly="False" ColumnEditorID="GridDropDownColumnEditor1">
        </telerik:GridDropDownColumn>

        <telerik:GridDropDownColumn DataField="OrgLevelID" DataSourceID="sqlGetOrgLevels"
            HeaderText="Org Level" ListTextField="OrgLevelDescription" ListValueField="OrgLevelID"
            UniqueName="CategoryID" ColumnEditorID="GridDropDownColumnEditor2">
        </telerik:GridDropDownColumn>

        <telerik:GridDateTimeColumn DataField="EffectiveDate" DataType="System.DateTime" PickerType="DatePicker" FilterControlAltText="Filter EffectiveDate column" HeaderText="Effective Date" SortExpression="EffectiveDate" UniqueName="EffectiveDate">
        </telerik:GridDateTimeColumn>

        <telerik:GridDateTimeColumn DataField="ExpirationDate" DataType="System.DateTime" PickerType="DatePicker" FilterControlAltText="Filter ExpirationDate column" HeaderText="Expiration Date" SortExpression="ExpirationDate" UniqueName="ExpirationDate">
        </telerik:GridDateTimeColumn>

        <telerik:GridBoundColumn DataField="SplitFactor" DataType="System.Decimal" FilterControlAltText="Filter SplitFactor column" HeaderText="Split Factor" SortExpression="SplitFactor" UniqueName="SplitFactor">
        </telerik:GridBoundColumn>

        <telerik:GridButtonColumn ConfirmText="Delete this product?" ConfirmDialogType="RadWindow"
            ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" Text="Delete"
            UniqueName="DeleteColumn">
            <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton"></ItemStyle>
        </telerik:GridButtonColumn>
    </Columns>


====================================================


            <InsertParameters>
                <asp:Parameter Direction="Input" Name="EmplID" Type="Int32"></asp:Parameter>
                <asp:Parameter Direction="Input" Name="PlanId" Type="Int32"></asp:Parameter>
                <asp:Parameter Direction="Input" Name="OrgLevelID" Type="String" />
                <asp:Parameter Direction="Input" Name="EffectiveDate" Type="DateTime" />
                <asp:Parameter Direction="Input" Name="ExpirationDate" Type="DateTime" />
                <asp:Parameter Direction="Input" Name="SplitFactor" Type="Decimal" />
            </InsertParameters>

Does it have something to do with the grid combo boxes ListTextField or ListValueField? Which does it pass to the stored proc?

Thanks
0
Maria Ilieva
Telerik team
answered on 29 Apr 2013, 08:35 AM
Hi,

Try attaching an event handler to the Insert event of the grid and inspect the e.Command.Parameters collection to see what parameters are being sent to the stored procedure and what value they have. In addition, you can also try setting a DefaultValue for the insert parameters and see if that makes any difference.

All the best,
Maria Ilieva
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Stefan
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Stefan
Top achievements
Rank 2
Maria Ilieva
Telerik team
Share this question
or