Can you populate the SqlCommand.Parameters collection for a stored procedure automatically? RRS feed

  • Question

  • Is there any method that will populate the SqlCommand.Parameters collection automatically? I am only interested if the command is a stored procedure. I guess it must be possible to writ the code myself that will go and query the metadata in SQL directly for the specified procedure and do this, but I wondered if there is a built in approach, or if someone has done this already? To give it some context see below -

                    using (SqlConnection sqlConnection = new SqlConnection(this.sqlConnectionString))
                        SqlCommand sqlCommand = new SqlCommand();
                        sqlCommand.CommandType = System.Data.CommandType.StoredProcedure;
                        sqlCommand.CommandText = Settings.Default.SqlStoredProcedure;
                        // sqlCommand.Parameters.Add.. - Do this bit for whatever the parameters are for my proc above 
                        // ....

    Monday, April 27, 2009 4:55 PM


All replies