Re: EditMode gets reset to adEditNone when adding multiple records
- From: Sven De Bont <SvenDeBont@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 25 Aug 2006 08:06:01 -0700
To be complete, the recordset contains UserGroups that are assigned to a
specific UserAccount. On the UI, 2 listboxes are shown: 1 that shows the
selected UserGroups (from the recordset I'm having problems with) and 1 that
shows the available UserGroups. The user can add/remove UserGroups from a
UserAccount by clicking a '>' button or a '<' button. I think you all can get
the idea :-)
I'll try to write down some of the code:
On the middle tier:
[begin code]
....
lstrSQL = Select ntuser_usergroup_id, ntuser_id, usergroup_id from
ntuser_usergroup where ntuser_id = " & vLngID
MakeConnection '<- connects to the db, connection is stored in local var
Set mRstTemp = New ADODB.Recordset
With mRstTemp
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockBatchOptimistic
.Open lstrSQL, mConConnection
end with
Set mRstTemp.ActiveConnection = Nothing
BreakConnection 'close the connection
[/end code]
The recordset in variable mRstTemp is the one the is returned to the client.
On the client, the recordset is bound to a TDBGrid control that doesn't allow
updates directly.
The actual code on the middle tier is split over a few classes & procedures,
but the sample above has all the important statements.
The code on the client, when the user clicks the button to add a UserGroup
to a UserAccount:
[begin code]
rstSelectedGroups.AddNew
rstSelectedGroups.Fields("ntuser_usergroup_id").Value =
GetNextSequece("SecurityID")
rstSelectedGroups.Fields("ntuser_id").Value =
rstUsers.Fields("ntuser_id").Value
rstSelectedGroups.Fields("usergroup_id").Value =
rstAvailableGroups.Fields("usergroup_id").Value
rstSelectedGroup.Update 'tried with commenting out this line, same effect
[/end code]
The actual code on the UI is also spread over multiple procedures, but this
is what actually happens
When the user finally clicks the save button, the recordset is send back to
the server, and the following code is executed on the middle tier:
[begin code]
MakeConnection '<- connects to the db, connection is stored in local var
Set vrstRecordSet.ActiveConnection = mConConnection
vrstRecordSet.UpdateBatch
set vrstRecordSet.ActiveConnection = Nothing
BreakConnection 'closed the connection
[/end code]
When I examine the recordset right before UpdateBatch is called, I can see
that all the records that were added are in the recordset, but only the last
one added gets stored in the database.
I'll check the value of the Status field as Stephen suggested and let you
know what my findings are.
And about the resetting of the EditMode Property...
According to this MS document
http://windowssdk.msdn.microsoft.com/en-us/library/ms677536.aspx , it doesn't
get reset when you call Update (Calling the Update method adds the new record
to the current Recordset, but the provider does not post the changes to the
underlying database, or reset the EditMode to adEditNone, until you call the
UpdateBatch method)
and according to this MS document
http://windowssdk.msdn.microsoft.com/en-us/library/ms681500.aspx , is does
(Calling the Update method adds the new record to the current Recordset and
resets the EditMode property to adEditNone, but the provider does not post
the changes to the underlying database until you call the UpdateBatch method.)
Go figure... :-)
Regards,
--
Sven De Bont - MCAD
"Stephen Howe" wrote:
.After I took a closer look, I found that the other added records werestill
in the recordset, but had their EditModeproperty reset to adEditNone (so
calling UpdateBatch has no effect on these records).
I think you are drawing the wrong conclusion from the wrong property.
Regardless of the state of EditMode property it has nothing to do with
UpdateBatch.
The EditMode property just indicates whether the current record is being
edited or not.
The right property is the Status for a record. This is a bit encoded field.
See
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdcstrecordstatusenum.asp
If you have done things correctly, if you iterate over your records, any new
records will have the bottom bit set (adRecNew).
I can't figure out where exactly the EditMode gets reset.
Probaby when do AddNew (does an implied Update if the current record is
changed) or on an explicit Update or on a
MoveNext/MovePrevious/MoveFirst/MoveNext
Does anyone have any idea what could cause the editmode property getting
reset to adEditNone?
ADO is causing it.
A small failing code example would be useful.
Stephen Howe
- References:
- Re: EditMode gets reset to adEditNone when adding multiple records
- From: Stephen Howe
- Re: EditMode gets reset to adEditNone when adding multiple records
- Prev by Date: Re: EditMode gets reset to adEditNone when adding multiple records
- Next by Date: Re: ADO error (80004003) on 1 machine
- Previous by thread: Re: EditMode gets reset to adEditNone when adding multiple records
- Next by thread: Re: EditMode gets reset to adEditNone when adding multiple records
- Index(es):