Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting record from ADO/SQL Server table raises exception 1

Status
Not open for further replies.

PManion

Programmer
Feb 11, 2002
13
US
I am using Delphi 5.0, accessing MS SQL Server 7.0 via the ADO components. On my form I have a TDBGrid, a TDBNavigator, a TDataSource, a TADOTable, and a TADOConnection object. My wish is to add, change, and delete records from the SQL Server table via the grid. However, whenever I attempt to delete a record from the grid, it raises this error message: "Row cannot be located for updating. Some values may have been changed since it was last read." Nevertheless the record is successfully deleted; if I close and reopen the table, the record is gone. What causes this? How do I fix it?

Thanks
 
I do not work with Ado but my literature says that the TADOTable has some limitations for INSERT, DELETE or UPDATE. Instead use TADOCommand or TADOQuery.

You could use:
TADOConnection <--- TADODataset <--- TDatasource <--- visual components

Set the property CommandType to cmdTable of the TADODataset

Regards S. van Els
SAvanEls@cq-link.sr
 
I tried your suggestion but the problem remains.

I tried using
(1) TADOTable with TableName <tablename>,
(2) TADODataSet with CommandType cmdTable and
CommandText <tablename>,
(3) TADODataSet with CommandType cmdTableDirect and
CommandText <tablename>, and
(4) TADODataSet with CommandType cmdText and
CommandText &quot;select * from <tablename>&quot;.

All raise the &quot;Row cannot be located...&quot; exception when a selected record is deleted from the grid, either by

(1) Pressing the subtract button on the TDBNavigator bar, or
(2) Pressing Ctrl-Del

Thank you for your reply; I appreciate your effort.

Any other suggestions?
 
I have been suffering from this problem as well. The solution I found was to use the following settings for my ado objects
CursorLocation = clUseServer
CursorType = clKeyset
LockType = ltOptimistic

using a serverside cursor does create enough overhead for the user to notice though.

I hope this helps. and let me know if you find a better solution.
 
That fixed it! I only had to change the CursorLocation from client-side to server-side, since the other properties were already as you recommend.

Many thanks.

P. Manion
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top