IBCPSession::BCPColFmt (OLE DB)
Creates a binding between program variables and SQL Server columns.
The BCPColFmt method is used to create a binding between BCP data file fields and SQL Server columns. It takes in the length, type, terminator, and prefix length of a column as parameters and sets each of these properties for individual fields.
If the user chooses interactive mode, this method is called twice; once to set the column format according to the default values (which are according to the type of the server column), and once to set the format according to the column type of the choice of the client chosen during interactive mode, for each column.
In non-interactive modes, it is called only once per column to set the type of each column to character or native type, and to set the column and row terminators.
The BCPColFmt method allows you to specify the user-file format for bulk copies. For bulk copy, a format contains the following parts:
A mapping from user-file fields to database columns.
The data type of each user-file field.
The length of the optional indicator for each field.
The maximum length of data per user-file field.
The optional terminating byte sequence for each field.
The length of the optional terminating byte sequence.
Each call to BCPColFmt specifies the format for one user-file field. For example, to change the default settings for three fields in a five-field user data file, first call BCPColumns(5), and then call BCPColFmt five times, with three of those calls setting your custom format. For the remaining two calls, set eUserDataType to BCP_TYPE_DEFAULT, and set cbIndicator, cbUserData, and cbUserDataTerm to 0, BCP_VARIABLE_LENGTH, and 0 respectively. This procedure copies all five columns, three with your customized format and two with the default format.
The IBCPSession::BCPColumns method must be called before any calls to BCPColFmt. You must call BCPColFmt once for each column in the user file. Calling BCPColFmt more than once for any user-file column causes an error.
You do not have to copy all of the data in a user file to a SQL Server table. To skip a column, specify the format of the data for the column setting the idxServerCol parameter to 0. In order to skip a field, you still need all the information for the method to work correctly.
Note The IBCPSession::BCPWriteFmt function can be used to persist the format specification provided through BCPColFmt.