Solved

Updating ADO Recordset

Posted on 2000-05-10
24
1,094 Views
Last Modified: 2007-10-18
I have an ADO Recordset, and i'm trying to edit a record in it. The problem is that when I try to edit a newly added record I receive this error message:

Run-time error'-2147217864 (80040e38)':

The specified row could not be located for updating: Some values may have been changed since it was last read.

However, if I restart my project and then try to edit the record it works.

I'm willing to give 100 points to the person who can tell me how the fix this problem.
0
Comment
Question by:IsaacRU
  • 9
  • 6
  • 4
  • +4
24 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 2798793
try using the .Update method after adding the new record
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2798915
Do a recordset.Resynch method after your Addnew. From MSDN:
--------------------------------------
PRB: Oracle Servers Convert Empty Strings to NULL

The information in this article applies to:

ActiveX Data Objects (ADO), versions 1.5, 2.0, 2.01, 2.1, 2.1 SP2, 2.5

SYMPTOMS
The Visual Basic Run-time error 80040e38, which follows, occurs when updating a record containing a variable-length string field previously set to the empty string:

The specified row could not be located for updating; Some values may have been changed since it was last read.

CAUSE
When setting a field to the empty string, Oracle servers automatically convert the empty string to NULL, but the object requesting the edit is not notified. The next time an edit is performed, the empty string is used to identify the record to update, and it is not found because the server now contains a NULL.

RESOLUTION
Two methods to resolve this follow:

Convert empty strings to NULL before editing a recordset object and submitting the update.

-or-

Execute the Recordset object's Resync method after editing.

MORE INFORMATION
The following Visual Basic (ActiveX Data Objects [ADO]) code illustrates the problem. The error occurs at the second Update method call.

Note that although this sample uses the Microsoft OLE DB Provider for Oracle, this behavior also occurs with the Microsoft ODBC Driver for Oracle. It is also possible to see the server's behavior with Oracle's SQL Plus. Issue an INSERT statement involving an empty string (''), and then issue a SELECT statement. The results of the SELECT will show NULL.

Steps to Reproduce Behavior
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset

Set cnn = New ADODB.Connection
cnn.Open "Provider=MSDAORA;Data Source=mydatasource;User ID=myid;Password=mypassword"
cnn.Execute "CREATE TABLE mytable (a NUMBER PRIMARY KEY, b VARCHAR2(10))"
cnn.Execute "INSERT INTO mytable VALUES (100,'value')"

Set rst = New ADODB.Recordset
rst.CursorLocation = adUseClient
rst.Open "SELECT * FROM mytable", cnn, adOpenStatic, adLockOptimistic
rst.MoveFirst
rst(1) = ""
rst.Update
rst(1) = "new"
rst.Update

rst.Close
cnn.Execute "DROP TABLE mytable"
cnn.Close

Set rst = Nothing
Set cnn = Nothing

The simplest work around for this problem is to use the Resync method on the recordset object as illustrated by this code example:
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset

Set cnn = New ADODB.Connection
cnn.Open "Provider=MSDAORA;Data Source=mydatasource;User ID=myid;Password=mypassword"
cnn.Execute "CREATE TABLE mytable (a NUMBER PRIMARY KEY, b VARCHAR2(10))"
cnn.Execute "INSERT INTO mytable VALUES (100,'value')"

Set rst = New ADODB.Recordset
rst.CursorLocation = adUseClient
rst.Open "SELECT * FROM mytable", cnn, adOpenStatic, adLockOptimistic
rst.MoveFirst
rst(1) = ""
rst.Update

rst.Resync

rst(1) = "new"
rst.Update

rst.Close
cnn.Execute "DROP TABLE mytable"
cnn.Close

Set rst = Nothing
Set cnn = Nothing
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 110 total points
ID: 2799059
Does your table/view have a Primary Key?
If not, ADO can't upate (add) the row correctly...

What is your database system?
0
 

Expert Comment

by:sergedornseiffer
ID: 2799526
If using a Database different than Access (like SqlSerrver or Oracle) ensure that you a unique key on the Table
0
 

Expert Comment

by:Surojitseal
ID: 2799679
I agree with wsh2.
I had the same problem and resync solved it.
0
 
LVL 2

Expert Comment

by:aidan_gill
ID: 2799933
i HAD THIS WITH Sybase and the primary key did the job
0
 

Expert Comment

by:sergedornseiffer
ID: 2800008
Does that mean I get my first points ???

I am brand-new here

0
 

Author Comment

by:IsaacRU
ID: 2801047
Thanks for all your comments. I'll try each one out and then give out the points

Thanks
0
 

Author Comment

by:IsaacRU
ID: 2801055
By the way AzraSound. I did call the update method after I added the record. But this did not solve the problem
0
 

Author Comment

by:IsaacRU
ID: 2801062
angelIII i'm using Access is my database system. Will i still need a primary key?
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2801068
wsh2's answer solved another question that was the exact same as yours just a few minutes ago...i imagine that is it
0
 

Author Comment

by:IsaacRU
ID: 2801093
When I tried to use the ADO Recordsets Resync method I got this error:

Run-time error '-2147467259 (80004005)':

Insufficient key column infomation for updating or refreshing.

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 28

Expert Comment

by:AzraSound
ID: 2801104
its a combination of errors produced from
a) what wsh2 said
b) what angelIII said
0
 

Author Comment

by:IsaacRU
ID: 2801168
Good point AzraSound.
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2801183
For your question of Primary Key:
Yes, you need a key!
You should have Primary Keys on every table...
I think you shouldn't need Resync...
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2801189
well someone just posted a question about getting the exact same error:

The specified row could not be located for updating.Some
values may have been changed since it was last read

and the solution was to use resynch
0
 

Author Comment

by:IsaacRU
ID: 2801209
I agree with you angelIII cause when i tried resync i got errors. AzraSound what was the title of the question you were talking about?
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2801213
Hi AzraSound,
I assume that you know ADO :-)
If yes, you certainly run already into the nice thing that ADO raises many errors, but with the same error number.
Even the error text is sometimes the same grrrr
More even, the error text is depending on same language settings, wich makes it difficult to simply analyse the Err.Description....
(developer's) life would be too easy, and our income too low :-)
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2801215
its now in the "answered section"  the accepted answer was the exact post the wsh2 has on this question...as a matter of fact, upon seeing the question i simply posted a link over to this question for the questioner to reference...i believe the question was named ".Update method and ADO Recordset"
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2801223
you have an income?  well we're two different entities all together then my friend
0
 

Author Comment

by:IsaacRU
ID: 2801255
angelIII you were right, when I added a primary key to the table it allowed the updates. Thanks Alot
0
 

Author Comment

by:IsaacRU
ID: 2801256
Adjusted points from 100 to 110
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2801271
It was a pleasure
0
 

Author Comment

by:IsaacRU
ID: 2801273
AzraSound, even though your answer was did not work for me, I was impressed how you got that information. Thanks
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now