I have an application that was converted from using DBLIB bcp to using ODBC bcp. All other field/data types bind are updated correctly, but dates put in the date
1753-01-01 00:00:00.000 when it should be NULL. The variable is a char [24] and the first item is set to \0 ( dbLoanBankruptcy.MotionforReliefReqDate[0] = NullChar; ).
Is there any example or way to put the date in as null when the variable is null and an actual date as needed?
bcp_bind(LoanBankruptcyDBPPtr, (BYTE *)&dbLoanBankruptcy.MotionforReliefReqDate, 0, 23, NULL, 0, SQLCHARACTER, 13)
Thank you,
Joel
Following site maybe helpful:
http://msdn2.microsoft.com/en-us/library/aa198011(sql.80).aspx
|||The link above only discusses dates enough to get an actual date into a table, but does not discuss how to get a NULL date stored. Is there a way to save <NULL>?
Would it be wrong to use the bcp_bind statement you needed for each row/record and re-bind each time? As in...
if(dbLoanBankruptcy.MotionforReliefFiledDate[0]==NullChar) {
if (bcp_bind(LoanBankruptcyDBPPtr, (BYTE *)&dbLoanBankruptcy.MotionforReliefFiledDate,0, SQL_NULL_DATA, NULL, 0, SQLVARCHAR, 14) == FAIL) LogBindError("LoanBankruptcy", "MotionforReliefFiledDate",LoanBankruptcyDBPPtr);
}else{
if (bcp_bind(LoanBankruptcyDBPPtr, (BYTE *)&dbLoanBankruptcy.MotionforReliefFiledDate,0, 23, NULL, 0, SQLVARCHAR, 14) == FAIL) LogBindError("LoanBankruptcy", "MotionforReliefFiledDate",LoanBankruptcyDBPPtr);
}
|||
You don't need to rebind each time
http://msdn2.microsoft.com/en-gb/library/aa177853(SQL.80).aspx
struct
{
int iIndicator;
char szDatetime[30];
} urBCPData;
if (bcp_bind(om_hDbc2, (LPCBYTE) &urBCPData, 4, SQL_VARLEN_DATA , NULL, 0,SQLVARCHAR, 1) == FAIL)
{
// Raise error and return.
return;
}
// Insert NULL
urBCPData.iIndicator = SQL_NULL_DATA;
if (bcp_sendrow(om_hDbc2) == FAIL)
{
// Raise error and return.
return;
}
// Insert 1753-01-01 00:00:00.000
urBCPData.iIndicator = 23;
strcpy(urBCPData.szDatetime, "1753-01-01 00:00:00.000");
if (bcp_sendrow(om_hDbc2) == FAIL)
{
// Raise error and return.
ShowSQLError(om_hDbc2, om_hStmt2);
return;
}
|||Tested and works... thanks.
The normal bind statement but the data portion is now (byte *)&data.datetime_struct
Code Snippet
if(dbLoanBankruptcy.MotionforReliefReqDate[0]==NullChar) {
dbLoanBankruptcy.bounddate.iIndicator = SQL_NULL_DATA;
}else{
dbLoanBankruptcy.bounddate.iIndicator = 24;
strcpy(dbLoanBankruptcy.bounddate.iValue, dbLoanBankruptcy.MotionforReliefReqDate);
}
No comments:
Post a Comment