locked
What to pass in UpdateParameter of SqlDataSource? RRS feed

  • Question

  • User1048433 posted

    Below is my Gridview

    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
            AllowSorting="True" AutoGenerateColumns="False"  DataSourceID="DataSource1">
      <Columns>
                <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
                <asp:BoundField DataField="id1" HeaderText="id1" ReadOnly="True" Visible="false"/>
                <asp:BoundField DataField="fn" HeaderText="first name" ReadOnly="False"/>
                <asp:BoundField DataField="add" HeaderText="address" InsertVisible="False" ReadOnly="False"/>
      </Columns>
    </asp:GridView>

    Below are the two stored procedure which I am using in SQL data source.

    alter procedure dbo.sp_select
    As
    Begin
      Select id1, fn, add from table1
    End
    
    alter procedure dbo.sp_update
      @TableID as int,
      @FirstName as varchar(50),
      @Address as varchar(50) 	
    As
    Begin
      update table1 set fn = @FirstName
    		    add = @Address
      Where	id1 = @TableID
    End
    


    In sp_select stored procedure, I am fetching orginal name from the table but in sp_update stored proceduire, it is accepting some other name as variable so Please suggest me that which parameter to pass in update parameter so it should work. Refer below the sql data source

    <asp:SqlDataSource ID="DataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:connstr1 %>" 
                            SelectCommand="sp_select" SelectCommandType="StoredProcedure"
                            UpdateCommand="sp_update" UpdateCommandType="StoredProcedure">
                   <SelectParameters>
                         <asp:SessionParameter DefaultValue="null" Name="vUserId" SessionField="UserName"/>
                   </SelectParameters>
                   <UpdateParameters>
                        <asp:SessionParameter DefaultValue="null" Name="vUserId" SessionField="UserName"/>
                        <asp:ControlParameter Name="vCommID" ControlId="GridView1"/>
                        <asp:ControlParameter Name="vCommDetail" ControlId="GridView1"/>
                        
     </UpdateParameters>

    Monday, August 4, 2014 6:06 AM

Answers

All replies

  • User-1360095595 posted

    You can remove the selectparameter since your select sp doesn't use any parameters. 

    You need to have three parameters in your updateparameters and use the same names add in your sp. Also change the BoundFields datafield to match the related names in the sp as well. 

    Monday, August 4, 2014 6:10 AM
  • User1048433 posted

    I am passing userid in select parameter that is why I cannot remove it.

    Is it necessary to have the same parameter name as in stored procedure for UpdateParameter to work? Bound field data is bound to sp_select stored procedure. It is working fine

    Monday, August 4, 2014 8:09 AM
  • User-1360095595 posted

    I am passing userid in select parameter that is why I cannot remove it.

    I don't know what that means. The sp_select procedure that you posted, which is set as the selectcommand for the datasource, does NOT have any parameters.

    Your <updateparameters> is a mess. I'm not sure what you're trying to do.

    Monday, August 4, 2014 10:16 AM
  • User1048433 posted

    In  Select parameter I am passing userID using session variable.
    Also, please suggest what should I do in update parameter.

    Tuesday, August 5, 2014 2:36 AM
  • User1918509225 posted

    Hi B9678123,

    According to your code ,you have three parameters in your store procedure "sp_update",

    While in your UpdateParameters ,you just set only one session  parameter for your sp.

    And The name in your ControlParameter is not  corresponsding to the  parameter's name in your sp.

    I suggest that you can refer to the link below about updateparameters in sqldatasource control:

    http://msdn.microsoft.com/en-US/us-cn/library/system.web.ui.webcontrols.sqldatasource.updateparameters(v=vs.110).aspx

    Hope it can help you.

    Best Regards,

    Kevin Shen.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 7, 2014 5:50 AM