Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Updating ADO Recordset

Posted on 2000-05-10
24
Medium Priority
?
1,137 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 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 440 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 
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 143

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 143

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 143

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

972 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