Aracılığıyla paylaş


bcp_writefmt

Oluşturur bir biçim dosyası geçerli toplu kopyalama veri dosyası biçimlerinin açıklamasını içeren.

RETCODE bcp_writefmt (
        HDBC hdbc,
        LPCTSTR szFormatFile);

Bağımsız değişkenler

  • hdbc
    Toplu kopyalama etkin ODBC bağlantı tanıtıcısı mı.

  • szFormatFile
    Yol ve dosya biçimi değerleri için veri dosyası almak için kullanıcı dosya adıdır.

Verir

BAŞARıLı veya BAŞARıSıZ.

Remarks

biçim dosyası toplu kopyalama tarafından oluşturulan bir veri dosyasına veri biçimini belirtir.Calls to bcp_columns and bcp_colfmt define the format of the data file.bcp_writefmt saves this definition in the file referenced by szFormatFile.Daha fazla bilgi için bkz: bcp_init.

Yapısı hakkında daha fazla bilgi için Kullanımıbcp veri biçimi dosyaları bakınBiçim dosyaları ile çalışma.

Kaydedilmiş bir biçimde bir dosya yüklemek için kullanın. bcp_readfmt.

Not

Tarafından üretilen biçim dosyası bcp_writefmt yalnızca sürümleri tarafından destekleniyorKullanımıbcp Dağıtılmış yardımcı programıSQL Server sürüm 7.0 ve üstü.

Örnek

// 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.

See Also

Reference