locked
error on selectparameters sqldatasource RRS feed

  • Question

  • User-1884529353 posted

    Hi all,

    i have a sqldatasource that i use to bind a gridview. 

    on the select commando of the sqldaasource i call a stored procedure with 3 parameter.

    the problem is that the gridview is not being bind. I use sqlserver profiler to trace the request at sqlserver and the code does not call the stored procedure. 

    what i am doing wrong??? thx in advance

     

     <asp:GridView ID="gridview" runat="server" AutoGenerateColumns="false" 
                GridLines="None" CssClass="grid-view" 
                PageSize="10"
                OnRowEditing="method_OnRowEditing"
                OnRowUpdating="method_RowUpdating"
                DataSourceID="sqldatasrc">
           <Columns>
    ...
           </Columns>
    </asp:GridView>

     

    <asp:SqlDataSource ID="sqldatasrc" runat="server" 
                 ConnectionString="<%$ ConnectionStrings:ConnectionStrings %>"
                ProviderName="<%$ ConnectionStrings:ConnectionStrings.ProviderName %>"
                OnSelected="method_OnSelected"
                OnUpdated="method_OnUpdated"
                SelectCommand="sp_selectdata" SelectCommandType="StoredProcedure"
                UpdateCommand="sp_updatedata" UpdateCommandType="StoredProcedure">
                
                 <SelectParameters>
                    <asp:Parameter Name="par1" Type="string"  />
                    <asp:Parameter Name="par2" Type="int32" ConvertEmptyStringToNull="true"  />
                    <asp:Parameter Name="par3" Type="string" ConvertEmptyStringToNull="true"/>
                </SelectParameters>
                <UpdateParameters>
                    <asp:Parameter Name="par1" Type="int32" />
                    <asp:Parameter Name="par2" Type="Int32" Direction="Output" />
                </UpdateParameters>
        </asp:SqlDataSource>

    on codebehind:

     

    protected void btnCerca_OnClick(object sender, ImageClickEventArgs e)
    {
    
            binding(txtval1.text, txtval2.text, txtval3.text);
    }
    
    private void binding(string val1, string val2, string val3)
     {
        sqldatasrc.SelectCommand = "sp_selectdata";
        sqldatasrc.SelectCommandType = SqlDataSourceCommandType.StoredProcedure;
        sqldatasrc.SelectParameters["par1"].DefaultValue = val1;
        sqldatasrc.SelectParameters["par2"].DefaultValue = val2;
        sqldatasrc.SelectParameters["par3"].DefaultValue = val3;
    }

     

     

    Wednesday, March 23, 2011 9:58 AM

Answers

  • User77042963 posted

    Try to add this one to your SqlDataSource:

    CancelSelectOnNullParameter

     

    ="false"

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 23, 2011 10:04 AM

All replies

  • User77042963 posted

    Try to add this one to your SqlDataSource:

    CancelSelectOnNullParameter

     

    ="false"

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 23, 2011 10:04 AM
  • User1288251396 posted

    It looks to me like you need to add "gridview.DataBind();" to your button handler.

     

    Wednesday, March 23, 2011 1:28 PM
  • User-1884529353 posted

    Thx a lot limno

    Thursday, March 24, 2011 5:20 AM