using Recordset update method

using Recordset update method

Post by junge » Fri, 18 Jul 2003 05:34:55



I'm trying to update a row by modifying the fields directly, but i can not
update if because
the RecordSet is ReadOnly after returns from Open(... and the cursor is
reseted to adOpenStatic..

I'm able to read and insert into Database but update fails.. ..why????
Whats wrong here???

  CString pcszSource(L"select * from MBDRstmt where TransID=10");
  VARIANT varTSQL;  VariantInit(&varTSQL);
  varTSQL.bstrVal=SysAllocString(pcszSource);
  varTSQL.vt=VT_BSTR;

  m_conn.spCON->put_Mode(adModeReadWrite); // adModeReadWrite=3

  _RecordsetPtr   spRS;
  CREATEiNSTANCE(spRS,Recordset);

  spRS->LockType = adLockOptimistic;
  spRS->CursorType = adOpenKeyset;

  HRESULT hr = spRS->Open( varTSQL
   ,(IDispatch*)m_conn.spCON
   , adOpenKeyset
   , adLockOptimistic
   , adCmdText);
    if(FAILED(hr))  return; // it never fails here.
  ConnectModeEnum mode;
  m_conn.spCON->get_Mode(&mode); // returns mode=15 instead 3
  spRS->MoveFirst();
  CursorTypeEnum cursor;
  spRS->get_CursorType(&cursor);// here cursor is already reseted to
adOpenStatic
  bool sopportUpdate = spRS->Supports(adUpdate); // returns false

 
 
 

1. Recordset Update Method

I'm having some problems with a simple database application. First, here's my
statistics.

OS       = Windows 3.1
Compiler = VC++ 1.5b
Database = Access 2.0

My application is very simple and is based largely from the database tutorial
in the "Microsoft Foundation Class Library" manual. Instead of keeping track
of classes I'm keeping track of people and addresses. In the tutorial when a
user chooses Record|Add they must enter their data and move off of the record
in order to commit the changes. If they choose Record|Add, enter their data
and immediately choose File|Exit the new record in never saved. I would like
for the current record to be saved whenever the user closes the application. I
created a message handler for the WM_DESTROY message in the FormView class. It
looks a little something like this:

void CAddressBookView::OnDestroy()
{
        if(m_bAddMode)
        {      
                TRY
                {
                        m_pSet->Update();
                }
                CATCH(CDBException, e)
                {
                        AfxMessageBox(e->m_strError);
                }
                END_CATCH
        }
        CRecordView::OnDestroy();

However, the application still behaves as before. I chose Record|Add, enter
the data for a new record and choose File|Exit without moving off of the newly
created record. The new record is still not being saved.

I suppose I could always just call OnMove in the OnDestroy method but that
doesn't seem quite "proper". Any insights would be much appreciated.

Mike Luton

2. Cannot boot with new HD and fresh XP install

3. SQL Server CE: Recordset AddNew method does not work

4. Ms-Dos

5. ADOCE recordset find method

6. Q: VC-Fortran mixed program build within Dev Studio?

7. Can′t use the FIND method in recordset

8. ECC support ???

9. The value method of a recordset in ADOCE

10. Recordset and connection execute method with SSCE

11. using ADOCE recordset object in emulator

12. append recordsets to a db using ActiveSync

13. DAO: using the results of one recordset query in another??