Writes a datafile format definition to a user file for a bulk copy between a file and SQL Server.
RETCODE bcp_writefmt (
PDBPROCESS dbproc,
LPCSTR filename );
where
SUCCEED or FAIL.
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.
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);
bcp_colfmt, bcp_columns, bcp_readfmt