How to pass parameters to stored procedure, which is used by sqlDataSource

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nitinp
    New Member
    • Aug 2006
    • 8

    How to pass parameters to stored procedure, which is used by sqlDataSource

    I want to bind GridView with sqlDataSource like following
    Code:
    sqlDataSource1.SelectCommand = "GET_TRACKING_INFO";
    sqlDataSource1.SelectCommandType = SqlDataSourceCommandType.StoredProcedure;
    				
    sqlDataSource1.SelectParameters.Add("Group_code",TypeCode.String, "1");
    sqlDataSource1.SelectParameters[0].Direction =ParameterDirection.Input; 
    
    GridView1.DataSource = sqlDataSource1;
    GridView1.DataBind();
    But raises error "Procedure or function GET_TRACKING_IN FO has too many arguments specified"

    When I execute this stored procedure in SQL query analyzer it works fine, there is no other parameter is used.

    Please tell me what is wrong with it. Very urgent.
    Last edited by Frinavale; Mar 9 '09, 03:06 PM. Reason: Added [code] tags: Please post code in [code] [/code] tags. (Moved to ASP.NET from .NET)
  • josephhamilton1
    New Member
    • Feb 2009
    • 1

    #2
    sqlDataSource1. SelectParameter s.Clear()

    GET_TRACKING_IN FO takes one argument I'm guessing.

    You're probably not clearing you input parameters on the 2nd time through.
    Put this at the beginning of the sub to be sure:

    sqlDataSource1. SelectParameter s.Clear()

    Otherwise, be sure that you're SP really does take a parameter.

    Comment

    • hajoabdul
      New Member
      • Mar 2009
      • 7

      #3
      Originally posted by nitinp
      I want to bind GridView with sqlDataSource like following

      sqlDataSource1. SelectCommand = "GET_TRACKING_I NFO";
      sqlDataSource1. SelectCommandTy pe = SqlDataSourceCo mmandType.Store dProcedure;

      sqlDataSource1. SelectParameter s.Add("Group_co de",TypeCode.St ring, "1");
      sqlDataSource1. SelectParameter s[0].Direction =ParameterDirec tion.Input;

      GridView1.DataS ource = sqlDataSource1;
      GridView1.DataB ind();

      But raises error "Procedure or function GET_TRACKING_IN FO has too many arguments specified"

      When I execute this stored procedure in SQL query analyzer it works fine, there is no other parameter is used.

      Please tell me what is wrong with it. Very urgent.
      ''''''''''''''' '''''''''''''''

      The reason for that error coming from your stored procedure is due to the fact that not all the parameters are being declared, either the ones in the stored procedures are less than the ones on the interface vice versa, so go through the both phases and make sure that there is equality in parameters

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Check out these articles for an example:

        Comment

        Working...