Showing posts with label posting. Show all posts
Showing posts with label posting. Show all posts

Thursday, February 16, 2012

ADO erroring under VS2005 that don't occur under VS2003

I've tried posting this question to the C++ forum - but no solutions there...

The following code fragment works when compiled in VS2003 on both Windows XP Pro (32-bit) and WindowsXP Pro x64.

However, when compiled under VS2005, the call to 'pMyRecordsetPtr->RecordCount' fails on both 32bit and 64bit WindowsXP.

I have tried #import'ing msado20.tlb and msado27.tlb.

Has anybody had any similar experience?

HRESULT hr = ::CoInitialize(NULL);

if (FAILED(hr))

{

return false;

}

_ConnectionPtr pConnection;

hr = pConnection.CreateInstance(__uuidof(Connection));

if (FAILED(hr))

{

return false;

}

try

{

//

_bstr_t strConnectionString = "Provider=sqloledb;Server=server1;Database=db1" ;

pConnection->CursorLocation = adUseClient ;

pConnection->Open(strConnectionString,

_T("user"), _T("pwd"), -1);

_CommandPtr pCommand(__uuidof(Command));

pCommand->ActiveConnection = pConnection;

pCommand->CommandText = "MyStoreProcedure";

pCommand->CommandType = adCmdStoredProc;

_RecordsetPtr pRecordSet = pCommand->Execute( 0, 0, 0 ) ;

// This fails
long lNumRecs = pRecordSet->RecordCount ;

pRecordSet->Close();

pConnection->Close();

::CoUninitialize();

}

catch (_com_error &e)

{

::CoUninitialize();

// ...

}

Dear Chappers, I get an error also, but no solution, sorry

Ado.cpp

h:\src\alarmlogger_vc2005\alarmview\debugobj\msado15.tli(111) : error C2065: '_result' : undeclared identifier

ADO erroring under VS2005 that don't occur under VS2003

I've tried posting this question to the C++ forum - but no solutions there...

The following code fragment works when compiled in VS2003 on both Windows XP Pro (32-bit) and WindowsXP Pro x64.

However, when compiled under VS2005, the call to 'pMyRecordsetPtr->RecordCount' fails on both 32bit and 64bit WindowsXP.

I have tried #import'ing msado20.tlb and msado27.tlb.

Has anybody had any similar experience?

HRESULT hr = ::CoInitialize(NULL);

if (FAILED(hr))

{

return false;

}

_ConnectionPtr pConnection;

hr = pConnection.CreateInstance(__uuidof(Connection));

if (FAILED(hr))

{

return false;

}

try

{

//

_bstr_t strConnectionString = "Provider=sqloledb;Server=server1;Database=db1" ;

pConnection->CursorLocation = adUseClient ;

pConnection->Open(strConnectionString,

_T("user"), _T("pwd"), -1);

_CommandPtr pCommand(__uuidof(Command));

pCommand->ActiveConnection = pConnection;

pCommand->CommandText = "MyStoreProcedure";

pCommand->CommandType = adCmdStoredProc;

_RecordsetPtr pRecordSet = pCommand->Execute( 0, 0, 0 ) ;

// This fails
long lNumRecs = pRecordSet->RecordCount ;

pRecordSet->Close();

pConnection->Close();

::CoUninitialize();

}

catch (_com_error &e)

{

::CoUninitialize();

// ...

}

Dear Chappers, I get an error also, but no solution, sorry

Ado.cpp

h:\src\alarmlogger_vc2005\alarmview\debugobj\msado15.tli(111) : error C2065: '_result' : undeclared identifier

Monday, February 13, 2012

ADO + MS Access Cannot use "date" as query condition

First I have to apologize about posting the problem here , since it not actually relate to SQL Server

I am really new to database programming.

I use ADO (the ActiveX one , Not ADO.NET) In an MFC Application to access MS ACCESS Database

I can insert date in to table using statement like this

insert into tableXXX (date_field) values ('1/2/2007')

but when i tried to query it using this statement

select * from tableXXX where date_field = #1/2/2007#

Nothing return

I also tried to use #1-2-2007# , #01-02-2007# but it all the same

Can someone tell me how to successfuly use date as a query condition ?

Thank in Advance

As far as I can remember from my access days you can also use the ISO format to query for dates in access:

= 20070201

Jens K. Suessmeyer

http://www.sqlserver2005.de

|||

It look like I have to subtract year with 543 (I use thai regional and standard/format setting),

But I still dont under stand why.

Since when I view it in Microsoft Access the date is correct as I inserted it (2007)

When I convert date return by "select" statement using COLEDateTime,It also autometicaly

subtract the year part with 543 (but nothing is done when using american standard/format)

Can somebody explain this to me?