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<CUserAcce ssor> > user;
CDBPropSet ps(DBPROPSET_ROWSET);
ps.AddProperty(DBPROP_IRow setChange, true);
ps.AddProperty(DBPROP_UPDA TABILITY, DBPROPVAL_UP_CHANGE | DBPROPVAL_UP_INSERT | DBPROPVAL_UP_DELETE);
ps.AddProperty(DBPROP_INIT _DATASOURC E, OLESTR("registrar"));
ps.AddProperty(DBPROP_IRow setUpdate, true);
if (SUCCEEDED(user.Open(m_Ses sion, _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.
I can read from the database fine, but when I try to update the record, it fails. Here is some code:
CTable<CAccessor<CUserAcce
CDBPropSet ps(DBPROPSET_ROWSET);
ps.AddProperty(DBPROP_IRow
ps.AddProperty(DBPROP_UPDA
ps.AddProperty(DBPROP_INIT
ps.AddProperty(DBPROP_IRow
if (SUCCEEDED(user.Open(m_Ses
{
}
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.
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
to correct this set every field status to ok ...( thru the constant)
before commiting the changes...
yosi
ASKER
I found the problem, I needed to remove this line:
ps.AddProperty(DBPROP_INIT _DATASOURC E, OLESTR("registrar"));
The database was already opened via the m_Session parameter
ps.AddProperty(DBPROP_INIT
The database was already opened via the m_Session parameter
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes, thanks!
You should move this property out of here and into the group used when opening the data source.