bcp_writefmt
van toepassing op:SQL Server
Azure SQL Database
Azure SQL Managed Instance
Azure Synapse Analytics
Analytics Platform System (PDW)
Hiermee maakt u een indelingsbestand met een beschrijving van de indeling van het huidige gegevensbestand voor bulksgewijs kopiëren.
Syntaxis
RETCODE bcp_writefmt (
HDBC hdbc,
LPCTSTR szFormatFile);
Unicode- en ANSI-namen:
- bcp_writefmtA (ANSI)
- bcp_writefmtW (Unicode)
Argumenten
hdbc-
Is de ODBC-verbindingshandgreep waarvoor bulksgewijs kopiëren is ingeschakeld.
szFormatFile-
Is het pad en de bestandsnaam van het gebruikersbestand voor het ontvangen van notatiewaarden voor het gegevensbestand.
Retourneert
SLAGEN OF MISLUKKEN.
Opmerkingen
Het indelingsbestand geeft de gegevensindeling op van een gegevensbestand dat is gemaakt door bulksgewijs te kopiëren. Aanroepen naar bcp_columns en bcp_colfmt de indeling van het gegevensbestand definiëren. bcp_writefmt slaat deze definitie op in het bestand waarnaar wordt verwezen door szFormatFile. Zie bcp_initvoor meer informatie.
Zie Bulkgegevens importeren en exporteren met behulp van het bcp-hulpprogramma (SQL Server)voor meer informatie over de structuur van bcp gegevensbestanden.
Als u een opgeslagen indelingsbestand wilt laden, gebruikt u bcp_readfmt.
Notitie
Het indelingsbestand dat door bcp_writefmt wordt geproduceerd, wordt alleen ondersteund door versies van het bcp-hulpprogramma gedistribueerd met SQL Server versie 7.0 en hoger.
Voorbeeld
// Variables like henv not specified.
HDBC hdbc;
DBINT nRowsProcessed;
// Application initiation, get an ODBC environment handle, allocate the
// hdbc, and so on.
...
// Enable bulk copy prior to connecting on allocated hdbc.
SQLSetConnectAttr(hdbc, SQL_COPT_SS_BCP, (SQLPOINTER) SQL_BCP_ON,
SQL_IS_INTEGER);
// Connect to the data source, return on error.
if (!SQL_SUCCEEDED(SQLConnect(hdbc, _T("myDSN"), SQL_NTS,
_T("myUser"), SQL_NTS, _T("myPwd"), SQL_NTS)))
{
// Raise error and return.
return;
}
// Initialize bulk copy.
if (bcp_init(hdbc, _T("myTable"), _T("myData.csv"),
_T("myErrors"), DB_OUT) == FAIL)
{
// Raise error and return.
return;
}
if (bcp_columns(hdbc, 3) == FAIL)
{
// Raise error and return.
return;
}
bcp_colfmt(hdbc, 1, SQLCHARACTER, 0, SQL_VARLEN_DATA, '\t', 1, 1);
bcp_colfmt(hdbc, 2, SQLCHARACTER, 0, SQL_VARLEN_DATA, '\t', 1, 2);
bcp_colfmt(hdbc, 3, SQLCHARACTER, 0, SQL_VARLEN_DATA, '\t', 1, 3);
if (bcp_writefmt(hdbc, _T("myFmtFile.fmt")) == FAIL)
{
// Raise error and return.
return;
}
if (bcp_exec(hdbc, &nRowsProcessed) == SUCCEED)
{
printf_s("%ld rows copied from SQL Server\n", nRowsProcessed);
}
// Carry on.