bcp_writefmt

Writes a datafile format definition to a user file for a bulk copy between a file and SQL Server.

Syntax

RETCODE bcp_writefmt (
PDBPROCESS
dbproc,
LPCSTR
filename );

where

dbproc
Is the DBPROCESS structure that is the handle for a particular workstation/ SQL Server process. It contains all the information that DB-Library uses to manage communications and data between the workstation and SQL Server.
filename
Is the full path and filename of the file containing the format definitions.

Returns

SUCCEED or FAIL.

Remarks

The format of the datafile reflects previous calls to bcp_columns and bcp_colfmt.

The bulk copy utility (bcp) copies a database table to or from a host file in a user-specified format, which can be saved with bcp in definition files that store the datafile format. These files can later automate the process of bulk copying files that share a common format. For more information on the bcp utility and definition files for datafile format, see the Microsoft SQL Server Transact-SQL Reference.

Read format-definition files with bcp_readfmt.

Note The file produced by bcp_writefmt is not compatible with versions of the bcp utility program before version 4.2.

Example

The following example shows how to use bcp_writefmt:

bcp_init(dbproc, "mytable", "bcpdata", "bcperrs", DB_OUT);

bcp_columns(dbproc, 3);
bcp_colfmt(dbproc, 1, SQLCHAR, 0, -1, '\t', 1, 1);
bcp_colfmt(dbproc, 2, SQLCHAR, 0, -1, '\t', 1, 2);
bcp_colfmt(dbproc, 3, SQLCHAR, 0, -1, '\t', 1, 3);

bcp_writefmt(dbproc, "my_fmtfile");

bcp_exec(dbproc, &rows_copied);

See Also

bcp_colfmt, bcp_columns, bcp_readfmt