ATL OLEDB Consumer Templates, SQL CE



Hi All,

I wrote a program to access some data from a SQL Server CE database (the
program is running on the Windows CE device.) I am able to use the ATL OLEDB
Consumer Templates (thanks to Joao Figueira) but I am unable to read a
"datetime" field.

I am using a CDynamicAccessor and am using the "GetValue" member function. I
know that I have to cast the return value to the correct type in order to
use the returned data. For example, I am receiving a string by doing:
CString str = (LPCTSTR)cmd.GetValue(1); for getting a string from column 1
(cmd is a CCommand object.) However, I am not sure what kind of cast I have
to do to access a "datetime" field. I tried the same cast as for a regular
string but I was unable to obtain the data that I expected. As I was
unsuccessful doing that, I have tried to use the "TranslateColumnNo"
function in conjunction with _GetDataPtr as follows:

cmd.MoveFirst();
,,,

ULONG ulNo = 1;
cmd.TranslateColumnNo(ulNo);

CString str = (LPCTSTR) (cmd._GetDataPtr(ulNo)); but I still got an emptry
string; then I tried using this:

cmd.GetInternalColumnNo(_T("ColumnName"), &ulNo);
CString str = (LPCTSTR) (cmd._GetDataPtr( ulNo)); // but I got some
garbage...


So, what kind of cast or how should one proceed to get a datetime field into
a CString using CDynamicAccessor?

Thanks!


.



Relevant Pages

  • Re: TryCast operand must be reference type
    ... you should not try a cast operation in your case (a cast is used to ... Your second line works simply because your "o" object is a string and you ... Dim dt As DateTime ...
    (microsoft.public.dotnet.general)
  • Re: TryCast operand must be reference type
    ... you should not try a cast operation in your case (a cast is used to ... Your second line works simply because your "o" object is a string and you ... Dim dt As DateTime ...
    (microsoft.public.dotnet.general)
  • Re: Convert.ToDateTime
    ... and you will need the cast (or the conversion) in order for the code ... If you know that the 16th field is a DateTime, ... or a string which represents a date? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: ADO.Net DateTime issue
    ... I specify the field I want ... Using (string) in front of the other ... values work for the other items, why does it not work for DateTime? ... > It's because of the cast, there is no implicit cast of a DateTime to ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: ADO.Net DateTime issue
    ... I specify the field I want ... Using (string) in front of the other ... values work for the other items, why does it not work for DateTime? ... > It's because of the cast, there is no implicit cast of a DateTime to ...
    (microsoft.public.dotnet.languages.csharp)

Loading