|
-
September 28th, 1999, 09:39 AM
#1
Autonumbers and CRecordSet::Requery()
Hi All,
I'm inserting a new record into a database using CRecordSet::AddNew, followed by CRecordSet::Update, However one of the key fields is an auto-number, I call the requery method, but it returns the first record. How do I get it to return the record I've just inserted?
Many Thanks
Daniel.
-
September 28th, 1999, 09:50 AM
#2
Re: Autonumbers and CRecordSet::Requery()
Hi,
Use CRecordset::m_strSort,like this:
rst.AddNew(..);
rst.Update(..);
rst.m_strSort="Your-auto-number-key-field DESC"
rst.Requery()
Hope this helps,
Oleg.
-
September 28th, 1999, 09:51 AM
#3
Re: Autonumbers and CRecordSet::Requery()
Requery using auto-number field as desc order, than get the field value and use it.
-
September 29th, 1999, 01:46 AM
#4
Re: Autonumbers and CRecordSet::Requery()
The filter method should work.....however I'm worried that should the database become busy, as many copies of the software should be running, that between the Update and Requery of one copy that another copy might call an AddNew and Update. This, I would assume, would return the record of the second application not the correct record of the first application.
Any Thoughts? Suggestions?
Thanks Daniel.
-
September 29th, 1999, 07:41 AM
#5
Re: Autonumbers and CRecordSet::Requery()
Hi Daniel.
You can open your recordset in the following modes:
- CRecordset: ynaset
- CRecordset::snapshot
- CRecordset: ynamic
- CRecordset::forwardOnly
A dynaset is a recordset with dynamic properties. During its lifetime, a recordset object in dynaset mode (usually called simply a “dynaset”) stays synchronized with the data source in the following way. In a multiuser environment, other users may edit or delete records that are in your dynaset or add records to the table your dynaset represents. Records your application adds to or deletes from the recordset are reflected in your dynaset. Records that other users add to the table will not be reflected in your dynaset until you rebuild the dynaset by calling its Requery member function. When other users delete records, MFC code skips over the deletions in your recordset. Other users’ editing changes to existing records are reflected in your dynaset as soon as you scroll to the affected record.
In the snapshot mode the membership and ordering of the records are determined when the recordset is opened; the data values are determined when the records are fetched. Changes made by other users are not visible until the recordset is closed and then reopened.
Dynamic recordsets (CRecordset: ynamic) are similar to dynasets; however, dynamic recordsets reflect any records added or deleted without calling CRecordset::Requery. For this reason, dynamic recordsets are generally expensive with respect to processing time on the DBMS, and many ODBC drivers do not support them.
The forwardOnly mode produce a read-only recordset with only forward scrolling.Changes made by other users are not visible until the recordset is closed and then reopened.
So, to avoid problems with unexpected changes in recordset by other applications - don't use CRecordset: ynamic mode.
Hope this helps,
Oleg.
-
September 29th, 1999, 09:27 AM
#6
Re: Autonumbers and CRecordSet::Requery()
After you did an .Update() do a .MoveLast()
There it is!
When using CRecordsets (dynaset) and adding a new record, that record will be placed at the end of the recordset.
... But I thought YOU did the backups...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|