Link to home
Start Free TrialLog in
Avatar of webview
webview

asked on

Trying to update record with ATL consumer template

I am trying to update a record in an Access database via the standard ATL consumer template classes (namely CTable).

I can read from the database fine, but when I try to update the record, it fails.  Here is some code:

CTable<CAccessor<CUserAccessor> > user;
 
CDBPropSet ps(DBPROPSET_ROWSET);

ps.AddProperty(DBPROP_IRowsetChange, true);
ps.AddProperty(DBPROP_UPDATABILITY, DBPROPVAL_UP_CHANGE | DBPROPVAL_UP_INSERT | DBPROPVAL_UP_DELETE);
ps.AddProperty(DBPROP_INIT_DATASOURCE, OLESTR("registrar"));
ps.AddProperty(DBPROP_IRowsetUpdate, true);

if (SUCCEEDED(user.Open(m_Session, _T("Users"), &ps)))
{
}

The above line fails with: DB_S_ERRORSOCCURRED

The session is opened succesfully and I can read records from hit (with CCommand).

The only thing I can think of is that the database is read-only, but it is not.


Avatar of paulburns
paulburns

One problem you've got is in including DBPROP_INIT_DATASOURCE in the property set. This property can only be used with the DBPROPSET_DBINIT group, you are trying to add it to a DBPROPSET_ROWSET group.

You should move this property out of here and into the group used when opening the data source.
I've seen a problem where u try to add a new record but get the error u mentioned..
to correct this set every field status to ok ...( thru the constant)
before commiting the changes...


yosi
Avatar of webview

ASKER

I found the problem, I needed to remove this line:

ps.AddProperty(DBPROP_INIT_DATASOURCE, OLESTR("registrar"));

The database was already opened via the m_Session parameter
ASKER CERTIFIED SOLUTION
Avatar of paulburns
paulburns

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of webview

ASKER

Yes, thanks!