bcp_bind
Binds data from a program variable to a table column for bulk copy into Microsoft SQL Server 2000.Syntax
RETCODE bcp_bind ( 
PDBPROCESS dbproc, 
LPCBYTE varaddr, 
INT prefixlen, 
DBINT varlen, 
LPCBYTE terminator, 
INT termlen,
INT type, 
INT table_column );ArgumentsterminatorIs a pointer to the byte pattern, if any, that s the end of this program variable. For example, C strings usually have a 1-byte terminator whose value is 0. If there is no terminator for the variable, set terminator to NULL. If you want to designate the C null terminator as the program variable terminator, use an empty string (" ") as terminator and set termlen to 1, because the null terminator constitutes a single byte. For instance, to use a C null terminator:bcp_bind (dbproc, co_name, 0, -1, "", 1, 0, 2)If there is no terminator:bcp_bind (dbproc, co_name, 0, -1, NULL, 0, 0, 2)楼主把你的那个NULL改为""试试。

解决方案 »

  1.   

    to  softj(天地客人<最近很迷茫>) 
      应该怎么设呀?
    TO  bugchen888(臭虫)
     改成""没用的。 用“”只是在字段为VARCHAR,TEXT等字符型时做为结束符用的。对于INT型的字段,
    下面的语句是可以用的。
    int nID;
    bcp_bind(hdbc, (BYTE*)&nID, 0, sizeof(DBINT), NULL, 0, SQLINT4, 1);
    bcp_sendrow(hdbc);
    这些语句运行正确,
    但是对于DECIMAL型的字段,
    float  f1;
    bcp_bind(hdbc, (BYTE*)&f1, 0, sizeof(DBDECIMAL), NULL, 0, SQLDECIMAL, 2);
    bcp_sendrow(hdbc);
    这些语句在bcp_sendrow时返回FAIL
    应该怎么用呀?
      

  2.   

    搞定了,这样写就行。
    int nID;
    float f1; if (bcp_bind(m_hdbc, (BYTE*)&nID, 0, sizeof(DBINT), NULL, 0, SQLINT4, 1) == FAIL)
    {
    return;
    }
    if (bcp_bind(m_hdbc, (BYTE*)&f1, 0, sizeof(DBFLT4), NULL, 0,SQLFLT4, 2) == FAIL)
    {
    return;
    } for(int i = 0; i < 10000; i++ )
    {
    nID = i;
    f1 = (float)i+1;
    if (bcp_sendrow(m_hdbc) == FAIL)
    {
    return;
    }
    if( i%1000 == 0)
    {
    bcp_batch(m_hdbc);
    } } DBINT      nRowsProcessed; if ((nRowsProcessed = bcp_done(m_hdbc)) == -1)
    {
    printf("Bulk-copy unsuccessful.\n");
    return;
    }