Hi,
Im trying to connect to my sql database and generally play around but I get the following error: error C3867: '_com_error::Description': function call missing argument list; use '&_com_error::Description' to create a pointer to member
I think it has something to do the import of the msado15.dll.
Obviously if I take out the error handling it runs but it returns random characters.
Anyone got any ideas?
#include <windows.h>
#include <stdio.h>
#import "C:\Program Files\Common Files\System\ADO\msado15.dll" \
no_namespace rename("EOF", "EndOfFile")
int main(int argc, char* argv[])
{
HRESULT hr = S_OK;
try
{
CoInitialize(NULL);
//Define string variables
_bstr_t strCnn("Provider=SQLOLEDB.1;Persist Security Info=False;"\
"User ID=Manager;Initial Catalog=DevTest;Data "\
"Source=WS-VISTA\\RICHY");
_RecordsetPtr pRstAuthors = NULL;
//Call Create instance to instantiate the Record Set
hr = pRstAuthors.CreateInstance(__uuidof(Recordset));
if(FAILED(hr))
{
printf("Failed creating record set instance\n");
return 0;
}
pRstAuthors->Open("SELECT Name,Number FROM TestTable",strCnn, adOpenStatic,
adLockReadOnly, adCmdText);
//Declare a variable of type _bstr_t
_bstr_t valField1;
int valField2;
pRstAuthors->MoveFirst();
//Loop through the record set
if(!pRstAuthors->EndOfFile)
{
while(!pRstAuthors->EndOfFile)
{
valField1 = pRstAuthors->Fields->GetItem("Name")->Value;
valField2 = pRstAuthors->Fields->GetItem("Number")->Value.intVal;
printf("%d - %s\n",valField2,(LPCSTR)valField1);
pRstAuthors->MoveNext();
}
}
}
catch(_com_error & ce)
{
printf("Error:%s\n,",ce.Description);
}
CoUninitialize();
return EXIT_SUCCESS;
}