Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

How to put milliseconds into an SQL datetime field using void RFX_Date(CFieldExchange* pFX, const char* szName, TIMESTAMP_STRUCT& value); ?

Avatar of tharstern
tharsternFlag for United Kingdom of Great Britain and Northern Ireland asked on
System ProgrammingEditors IDEs
4 Comments1 Solution1936 ViewsLast Modified:
I have a class that wraps CRecordset to read/write values to an SQL table using ODBC.

I recently discovered however that when dealing with datetime fields the milliseconds were being lost.

So I looked up RFX_Date and did some googling to find that the version we had used was the CTime version, which has no milliseconds.

OK, so I changed my class from using CTimes to TIMESTAMP_STRUCT.

I ran my code and stepped through and could now see the milliseconds being valid using the following code where m_tDate is the TIMESTAMP_STRUCT which is used in the RFX_Date.

The problem is it isn't actually working! The value in the table is still truncated to the nearest second. I have checked using SQL Server 2005 management studio.

I have also tried using a COleDateTime but also debugs fine but doesn't actually put the milliseconds into the table datetime field.

What am I missing?
Thanks.
// From the header
TIMESTAMP_STRUCT m_Date;
 
// From the source
CProductHistorySet::CProductHistorySet(CDatabase* pdb)
	: CRecordset(pdb)
{
	m_nDefaultType = dynaset;
 
	SYSTEMTIME sysTime;
 
	::GetSystemTime(&sysTime);
 
	m_Date.year = sysTime.wYear;
	m_Date.month = sysTime.wMonth;
	m_Date.day = sysTime.wDay;
	m_Date.hour = sysTime.wHour;
	m_Date.minute = sysTime.wMinute;
	m_Date.second = sysTime.wSecond;
	m_Date.fraction = sysTime.wMilliseconds;
}
 
void CProductHistorySet::DoFieldExchange(CFieldExchange* pFX)
{
	//{{AFX_FIELD_MAP(CProductHistorySet)
	pFX->SetFieldType(CFieldExchange::outputColumn);
	RFX_Date(pFX, _T("[Datedb]"), m_Date);
...
}
ASKER CERTIFIED SOLUTION
Avatar of tharstern
tharsternFlag of United Kingdom of Great Britain and Northern Ireland image

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answers