Deriving Parameters

Listing 19.5 shows how to invoke a call that requires multiple parameters. This type of code, however, can be unmanageable because database specifics such as the parameters’ names and data types are hard-coded into your source code.

You can use the CommandBuilder class, which essentially queries the database for metadata about the parameters and populates the SqlCommand object with that information. Therefore, you only have to specify the values. Listing 19.7 shows the alternative code from Listing 19.5.

Listing 19.7. Specifying Parameters Using CommandBuilder
1: program storedproc_cb; 2: 3: {$APPTYPE CONSOLE} 4: 5: {%DotNetAssemblyCompiler 'c:\windows\microsoft.net\framework\v1.1.4322\System.Data.dll'} 6: 7: uses 8: SysUtils, ...

Get Delphi for .NET Developer’s Guide 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.