Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Liest eine Datendatei-Formatdefinition aus der angegebenen Formatdatei.
Syntax
RETCODE bcp_readfmt (
HDBC
hdbc
,
LPCTSTR
szFormatFile
);
Argumente
hdbc
Das für den Massenkopiervorgang aktivierte ODBC-Verbindungshandle.
szFormatFile
Pfad und Dateiname der Datei, die die Formatwerte für die Datendatei enthält.
Rückkehr
SUCCEED oder FAIL.
Bemerkungen
Nach bcp_readfmt
dem Lesen der Formatwerte werden die entsprechenden Aufrufe an bcp_columns und bcp_colfmt. Sie brauchen keine Formatdatei zu analysieren, um diese Aufrufe zu tätigen.
Rufen Sie bcp_writefmt auf, um eine Formatdatei beizubehalten. Aufrufe können bcp_readfmt
auf gespeicherte Formate verweisen. Weitere Informationen finden Sie unter bcp_init.
Alternativ kann das Hilfsprogramm für Massenkopien (bcp) benutzerdefinierte Datenformate in Dateien speichern, auf bcp_readfmt
die verwiesen werden kann. Weitere Informationen zum bcp-Hilfsprogramm und zur Struktur von bcp-Datenformatdateien finden Sie unter Massenimport und -export von Daten (SQL Server).For more information about the bcp utility and the structure of bcp data format files, see Bulk Import and Export of Data (SQL Server).For more information about the structure of bcp data format files, see Bulk Import and Export of Data (SQL Server).
Der BCPDELAYREADFMT
Wert des eOption-Parameters von bcp_control ändert das Verhalten von bcp_readfmt.
Hinweis
Die Formatdatei muss von Version 4.2 oder höher des bcp-Hilfsprogramms erstellt worden sein.
Beispiel
// 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_IN) == FAIL)
{
// Raise error and return.
return;
}
if (bcp_readfmt(hdbc, _T("myFmtFile.fmt")) == FAIL)
{
// Raise error and return.
return;
}
if (bcp_exec(hdbc, &nRowsProcessed) == SUCCEED)
{
cout << nRowsProcessed << " rows copied to SQL Server\n";
}
// Carry on.