Writes a data file format definition to a user file for a bulk copy between a file and Microsoft® SQL Server™.
RETCODE bcp_writefmt (
PDBPROCESS dbproc,
LPCSTR file_name );
SUCCEED or FAIL.
The format of the data file 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 data file format. These files can later automate the process of bulk copying files that share a common format.
Read format-definition files with bcp_readfmt.
Note The file produced by bcp_writefmt is not compatible with versions of the bcp utility 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_readfmt |
bcp_columns |