locked
Passing parameters to a stored procedure RRS feed

  • Question

  • Hi.

    What is the most efficient way of sending/passing parameters to a stored procedure from ADO.NET ?

    Should I concatenate all the fields into a pipe delimited text stream and unpack in the procedure ?

    Is there a way to pass xml into a procedure and unpack that ?

    Thanks...
    Tuesday, May 25, 2010 2:02 PM

Answers

  • how many parameters are you trying to send? can you post the code you've written so far?

    I usually use this method. something more or less

    cmd.Parameters.Add(new SqlParameter("@CustomerID", custId))


    Best Regards,
    Melissa Suciadi


    If you have found this post helpful, please click the 'Vote as Helpful ' link (the green triangle and number on the top-left).

    If this post answers your question, click the 'Mark As Answered ' link below. It helps others who experience the same issue in future to find the solution.

    • Proposed as answer by Naomi N Tuesday, May 25, 2010 2:38 PM
    • Marked as answer by KJian_ Monday, May 31, 2010 3:21 AM
    Tuesday, May 25, 2010 2:12 PM
  • Depends on the number of parameters. You also certainly can pass XML parameter from ADO.NET
    Premature optimization is the root of all evil in programming. (c) by Donald Knuth

    Naomi Nosonovsky, Sr. Programmer-Analyst

    My blog
    • Marked as answer by KJian_ Monday, May 31, 2010 3:21 AM
    Tuesday, May 25, 2010 2:39 PM
  • If you are using SQLSERVER 2008 , consider using table valued parameters.
    • Marked as answer by KJian_ Monday, May 31, 2010 3:21 AM
    Tuesday, May 25, 2010 2:46 PM

All replies

  • how many parameters are you trying to send? can you post the code you've written so far?

    I usually use this method. something more or less

    cmd.Parameters.Add(new SqlParameter("@CustomerID", custId))


    Best Regards,
    Melissa Suciadi


    If you have found this post helpful, please click the 'Vote as Helpful ' link (the green triangle and number on the top-left).

    If this post answers your question, click the 'Mark As Answered ' link below. It helps others who experience the same issue in future to find the solution.

    • Proposed as answer by Naomi N Tuesday, May 25, 2010 2:38 PM
    • Marked as answer by KJian_ Monday, May 31, 2010 3:21 AM
    Tuesday, May 25, 2010 2:12 PM
  • Depends on the number of parameters. You also certainly can pass XML parameter from ADO.NET
    Premature optimization is the root of all evil in programming. (c) by Donald Knuth

    Naomi Nosonovsky, Sr. Programmer-Analyst

    My blog
    • Marked as answer by KJian_ Monday, May 31, 2010 3:21 AM
    Tuesday, May 25, 2010 2:39 PM
  • If you are using SQLSERVER 2008 , consider using table valued parameters.
    • Marked as answer by KJian_ Monday, May 31, 2010 3:21 AM
    Tuesday, May 25, 2010 2:46 PM
  • If you go with the latest suggestion, take a look at this great article explaining how to pass them from C# code

    http://lennilobel.wordpress.com/2009/07/29/sql-server-2008-table-valued-parameters-and-c-custom-iterators-a-match-made-in-heaven/


    Premature optimization is the root of all evil in programming. (c) by Donald Knuth

    Naomi Nosonovsky, Sr. Programmer-Analyst

    My blog
    Tuesday, May 25, 2010 3:02 PM