ODBC and SQL Server

Binding Parameters

Each parameter marker in an SQL statement must be associated, or bound, to a variable in the application before the statement can be executed. This is done by calling the SQLBindParameter function. SQLBindParameter describes the program variable (address, C data type, and so on) to the driver. It also identifies the parameter marker by indicating its ordinal value and then describes the characteristics of the SQL object it represents (SQL data type, precision, and so on).

Parameter markers can be bound or rebound at any time before a statement is executed. A parameter binding remains in effect until one of the following occurs:

An application can also bind parameters to arrays of program variables to process an SQL statement in batches. There are two types of array binding:

When the Microsoft® SQL Server™ ODBC driver sends character or binary string parameters to the server, it pads the values to the length specified in SQLBindParameter ColumnSize parameter. If an ODBC 2.x application specifies 0 for ColumnSize, the driver pads the parameter value to the precision of the data type. The precision is 8000 when connected to SQL Server servers, 255 when connected to earlier versions of SQL Server. ColumnSize is in bytes for variant columns.

SQL Server supports defining names for stored procedure parameters. ODBC 3.5 also introduced support for named parameters used when calling SQL Server stored procedures. This support can be used to:

Named parameters are only supported when using the Transact-SQL EXECUTE statement or the ODBC CALL escape sequence to execute a stored procedure.

For more information about examples of using named parameters, see ODBC 3.0 Software Developers Kit and Programmer's Reference.

See Also

SQLBindParameter

SQLFreeStmt

SQLSetStmtAttr