How to insert a DBTIMESTAMP type of data using OLE DB

Tech-Archive recommends: Fix windows errors by optimizing your registry



Hi,

I am using OLE DB to access a Microsoft SQL Server database.

The MFC generated Accessor code is like this:
class CdboScannersAccessor
{
public:
TCHAR m_ScannerID[33];
LONG m_Scans;
DBTIMESTAMP m_LastCalibration;
DBTIMESTAMP m_LastBeltCleaning;

BEGIN_COLUMN_MAP(CdboScannersAccessor)
COLUMN_ENTRY(1, m_ScannerID)
COLUMN_ENTRY(2, m_Scans)
COLUMN_ENTRY(3, m_LastCalibration)
COLUMN_ENTRY(4, m_LastBeltCleaning)
END_COLUMN_MAP()

DEFINE_COMMAND(CdboScannersAccessor, _T(" \
SELECT \
\"Scanner ID\", \
Scans, \
\"Last Calibration\", \
\"Last Belt Cleaning\" \
FROM dbo.Scanners"))

// You may wish to call this function if you are inserting a record and
wish to
// initialize all the fields, if you are not going to explicitly set all of
them.
void ClearRecord()
{
memset(this, 0, sizeof(*this));
}
};

Column 3 and 4 are smalldatetime types and allow nulls.

When I use the following code to insert a new record into the table, I got
error -2147467259 (0x80004005).
CdboScanners dboScanners;
if (dboScanners.Open() == S_OK)
{
strcpy(dboScanners.m_ScannerID, "00001");
dboScanners.m_Scans = 100;
dboScanners.m_LastCalibration.year = 2005;
dboScanners.m_LastCalibration.month = 6;
dboScanners.m_LastCalibration.day = 6;
dboScanners.m_LastCalibration.hour = 12;
dboScanners.m_LastCalibration.minute = 30;
dboScanners.m_LastCalibration.second = 0;
hr = dboScanners.Insert(); // hr is -2147467259
}

Am I do anything wrong? Any help would be appreciated.

Clayton
.