Alain Royer
October 12th, 2000, 09:48 AM
This is a simple programme that open a database that contain a contacts list and display it.
Then I want to change the last name of the firt person to "Grondin" and that doesnt work.
Thanks for your help!!!
#import "c:\program files\fichiers communs\system\ado\msado15.dll" no_namespace rename("EOF", "adoEOF")
#ifdef _WINDOWS_
#undef _WINDOWS_
#endif
#include
#include
#include
#include "util_mfc.h"
#include "icrsint.h"
class CContacts : public CADORecordBinding
{
BEGIN_ADO_BINDING(CContacts)
ADO_VARIABLE_LENGTH_ENTRY2(1, adVarChar, m_au_id, sizeof(m_au_id), lau_idStatus, TRUE)
ADO_VARIABLE_LENGTH_ENTRY2(2, adVarChar, m_au_fname, sizeof(m_au_fname), lau_fnameStatus, TRUE)
ADO_VARIABLE_LENGTH_ENTRY2(3, adVarChar, m_au_lname, sizeof(m_au_lname), lau_lnameStatus, TRUE)
ADO_VARIABLE_LENGTH_ENTRY2(4, adDate, m_au_date, sizeof(m_au_date), lau_dateStatus, TRUE)
END_ADO_BINDING()
public:
char m_au_id[21];
ULONG lau_idStatus;
char m_au_fname[51];
ULONG lau_fnameStatus;
char m_au_lname[51];
ULONG lau_lnameStatus;
COleDateTime m_au_date;
ULONG lau_dateStatus;
};
int main()
{
CString strConnection;
if (FAILED(::CoInitialize(NULL)))
{
return 0;
}
if (!GetConnectionStringFromUDL("d:\\test_jet.udl", strConnection))
{
return 0;
}
try
{
_ConnectionPtr pConnection = NULL;
_CommandPtr pCommand = NULL;
_RecordsetPtr pRecordset = NULL;
CContacts contacts;
IADORecordBinding *picRecordset = NULL;
TESTHR(pConnection.CreateInstance(_uuidof(Connection)));
TESTHR(pRecordset.CreateInstance(_uuidof(Recordset)));
TESTHR(pCommand.CreateInstance(_uuidof(Command)));
pConnection->Open((_bstr_t)strConnection, "", "", NULL);
pCommand->PutActiveConnection(_variant_t((IDispatch *)pConnection));
pCommand->CommandText = "SELECT * FROM Contacts";
pRecordset = pCommand->Execute(NULL, NULL, adCmdText);
TESTHR(pRecordset->QueryInterface(__uuidof(IADORecordBinding), (LPVOID *) &picRecordset));
TESTHR(picRecordset->BindToRecordset(&contacts));
while(!pRecordset->adoEOF)
{
printf("%s, %s %i/%i/%i\n", contacts.m_au_lname, contacts.m_au_fname, contacts.m_au_date.GetYear(), contacts.m_au_date.GetMonth(), contacts.m_au_date.GetDay());
pRecordset->MoveNext();
}
pRecordset->MoveFirst();
memcpy(contacts.m_au_lname, "Grondin\0", 8);
TESTHR(picRecordset->Update(&contacts)); // HERE!!!!!!!
if (picRecordset)
{
picRecordset->Release();
}
pRecordset->Close();
pConnection->Close();
}
catch(_com_error &e)
{
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
printf("erreur: %s, %s\n", (LPCSTR)bstrSource, (LPCSTR)bstrDescription);
}
getch();
::CoUninitialize();
return 1;
}
Then I want to change the last name of the firt person to "Grondin" and that doesnt work.
Thanks for your help!!!
#import "c:\program files\fichiers communs\system\ado\msado15.dll" no_namespace rename("EOF", "adoEOF")
#ifdef _WINDOWS_
#undef _WINDOWS_
#endif
#include
#include
#include
#include "util_mfc.h"
#include "icrsint.h"
class CContacts : public CADORecordBinding
{
BEGIN_ADO_BINDING(CContacts)
ADO_VARIABLE_LENGTH_ENTRY2(1, adVarChar, m_au_id, sizeof(m_au_id), lau_idStatus, TRUE)
ADO_VARIABLE_LENGTH_ENTRY2(2, adVarChar, m_au_fname, sizeof(m_au_fname), lau_fnameStatus, TRUE)
ADO_VARIABLE_LENGTH_ENTRY2(3, adVarChar, m_au_lname, sizeof(m_au_lname), lau_lnameStatus, TRUE)
ADO_VARIABLE_LENGTH_ENTRY2(4, adDate, m_au_date, sizeof(m_au_date), lau_dateStatus, TRUE)
END_ADO_BINDING()
public:
char m_au_id[21];
ULONG lau_idStatus;
char m_au_fname[51];
ULONG lau_fnameStatus;
char m_au_lname[51];
ULONG lau_lnameStatus;
COleDateTime m_au_date;
ULONG lau_dateStatus;
};
int main()
{
CString strConnection;
if (FAILED(::CoInitialize(NULL)))
{
return 0;
}
if (!GetConnectionStringFromUDL("d:\\test_jet.udl", strConnection))
{
return 0;
}
try
{
_ConnectionPtr pConnection = NULL;
_CommandPtr pCommand = NULL;
_RecordsetPtr pRecordset = NULL;
CContacts contacts;
IADORecordBinding *picRecordset = NULL;
TESTHR(pConnection.CreateInstance(_uuidof(Connection)));
TESTHR(pRecordset.CreateInstance(_uuidof(Recordset)));
TESTHR(pCommand.CreateInstance(_uuidof(Command)));
pConnection->Open((_bstr_t)strConnection, "", "", NULL);
pCommand->PutActiveConnection(_variant_t((IDispatch *)pConnection));
pCommand->CommandText = "SELECT * FROM Contacts";
pRecordset = pCommand->Execute(NULL, NULL, adCmdText);
TESTHR(pRecordset->QueryInterface(__uuidof(IADORecordBinding), (LPVOID *) &picRecordset));
TESTHR(picRecordset->BindToRecordset(&contacts));
while(!pRecordset->adoEOF)
{
printf("%s, %s %i/%i/%i\n", contacts.m_au_lname, contacts.m_au_fname, contacts.m_au_date.GetYear(), contacts.m_au_date.GetMonth(), contacts.m_au_date.GetDay());
pRecordset->MoveNext();
}
pRecordset->MoveFirst();
memcpy(contacts.m_au_lname, "Grondin\0", 8);
TESTHR(picRecordset->Update(&contacts)); // HERE!!!!!!!
if (picRecordset)
{
picRecordset->Release();
}
pRecordset->Close();
pConnection->Close();
}
catch(_com_error &e)
{
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
printf("erreur: %s, %s\n", (LPCSTR)bstrSource, (LPCSTR)bstrDescription);
}
getch();
::CoUninitialize();
return 1;
}