Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6696873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:23:34+00:00 2026-05-26T06:23:34+00:00

I have an Visual C++ (MFC) application using ADO to access a Microsoft SQL

  • 0

I have an Visual C++ (MFC) application using ADO to access a Microsoft SQL Server database. I’d like to start using DateTimeOffset columns but I’m getting an exception.

Here’s a code snippet:

HRESULT hRes = pRecordset.CreateInstance(__uuidof(Recordset));
FieldPtr fieldPtr = pRecordset->Fields->GetItem(bstrFieldName);
DataTypeEnum type = fieldPtr->Type;
_variant_t vFieldValue = fieldPtr->Value;

Assigning Value to a _variant_t throws 0x80020008 Bad variable type.

fieldPtr->Type is 146 for DateTimeOffset fields. Understandably, as ADO 2.8 presumably pre-dates this column type, 146 isn’t in DataTypeEnum. However, I know that I can access these fields in classic ASP, which is also ADO 2.8.

How do I access this column?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:23:35+00:00Added an answer on May 26, 2026 at 6:23 am

    Microsoft provides support for downlevel clients by casting DateTimeOffset to a string type.

    This means that where Provider=SQLOLEDB, DateTimeOffset will be returned as a string. (This explains why I was successfully able to access the field using classic ASP).

    If you’re using a more recent provider such as SQL Server Native Client 10.0 OLE DB Provider (Provider=SQLNCLI10), you’ll need a different approach.

    The simplest approach is to cast to a varchar in the SELECT statement:

    SELECT CAST(SYSDATETIMEOFFSET() AS VARCHAR(34))
    

    An alternative is to use VARIANT to access the value as a double (dblVal) and convert from that. For example:

    HRESULT hRes = pRecordset.CreateInstance(__uuidof(Recordset));
    FieldPtr fieldPtr = pRecordset->Fields->GetItem(bstrFieldName);
    VARIANT v;
    VariantInit(&v);
    fieldPtr->get_Value(&v);
    _bstr_t bstrTime = v.bstrVal;
    VariantClear(&v);
    

    However, I’m not aware of a library that will convert the floating point representation to something more useable so there’s some additional work to do there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a window application in visual c++. I am not using MFC I
I have a windows application in visual C++. I am not using MFC, in
I have a Window (win32 API) Application in visual c++. I am not using
I have a Window (win32 API) Application in visual c++. I am not using
I have experience developing MFC applications with C++ using Visual Studio 6.0. You can
I have rewrited a simple MFC application in MS Visual Studio 2008, and now
I have a MFC dialog in Visual C++ 2005, (MFC Application) and I have
We have a large Visual Studio 2005 C++/Mfc solution, 1 project with around 1300
I have Visual Studio 2005 Professional ENU installed and want to create GUIDs using
I have Visual Studio 2008 and the Windows SDK for Windows Server 2008 and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.