How to add parameters from stored procedures.

hi is there a way of programmatically adding a stored procedure parameters to a parameter collection


Answer this question

How to add parameters from stored procedures.

  • oulisee

    Look for the method DeriveParameters in SqlCommandBuilder (or OracleCommandBuilder or whatever provider are you using) -SqlCommandBuilder.DeriveParameters(command) will do what you want for Sql Server


  • Brendan77655

    well what i meant is that after declaring your a command etc like you did.
    i was thinking since the stored procedure already has the parameters and their types on the database is it possible to just load these automatically into myParam with having to add them manually

  • thames

    do you mean this:




    SqlCommand theSQLCommand = new SqlCommand("stored_proc_name");
    theSQLCommand.CommandType == CommandType.StoredProcedure;

    SqlParameter myParam = new SqlParameter("@param1", sqldbtype.int);
    myParam.Value = 0

    theSQLCommand.Parameters.Add(myParam);
    ..




  • Yngwie

    You'll probably want to use SQLDMO to retrieve the stored proc and it's properties (like parameters, etc).

    Here's a decent article on using it from C# http://www.csharphelp.com/archives2/archive342.html


  • How to add parameters from stored procedures.