Managed Commands with Stored Procedures
Although the example in Listing 3.5 allows you to evaluate data and output only what is desired, a more economical way to get a restricted result set is to use a SQL statement with a WHERE clause. Rather than querying the data store and bringing back all of the records in the table, you can write a SQL statement or stored procedure to bring back only the data you want. Stored procedures typically give better performance to your application than a SQL statement passed via a command.
You can use the Managed Command to call a stored procedure. In many cases, the stored procedure will have the parameters you pass it to determine the result set, such as the country abbreviation in the previous examples.
Get Programming Data-Driven Web Applications with ASP.NET now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.