Solved

Deleting Records using an ado.recordset object

Posted on 2003-11-29
8
1,310 Views
Last Modified: 2013-12-25
Hi guys,
I'm a newbie so please just bear with me. I'm trying to delete all records using an ado.recordset object. i tried using the ff. code:
     With adotable.recordset
      If .recordcount > 0 then
            .movefirst
            do while not .eof
                 .delete
                 .movenext
            loop
      End if
   End with
this fails and give me an error that sez "Key column information is insufficient or incorrect, too many rows were affected by update". i'm using a datagrid to display the records. Hope you cud help thanks.

0
Comment
Question by:Jangomez74
8 Comments
 
LVL 50

Expert Comment

by:Lowfatspread
Comment Utility
Hi Jangomez74,

whats your recordset based on?
how many actual tables are involved...

 


Cheers!
0
 
LVL 3

Expert Comment

by:daffyduck14mil
Comment Utility
Hi,

As LowFatSpread said, most likley you have a recordset object with more then one table in it. ADO doesn't know what table or record to delete, since it cascade's down the query.

For the most effiecient way to empty a table, as I read you are trying to do, is to create an sql query that does that. For example, we have a table named "Customers".

Now, to create a SQL query that empty's that table, simple use the following:

DELETE
FROM Customers

Execute that on either a command object, or on your connection object. Delete query's can be given a where clause, that causes a certain amount of records to be deleted where the field matches the criteria you give it. Just like a select does.

Hope this helps you somewhat.

Grtz.©

D.
0
 
LVL 33

Expert Comment

by:hongjun
Comment Utility
one simple example.

dim conn as adodb.connection
dim strsql as string

set conn = new adodb.connection
conn.open "DSN=mydsn"  ' your connection string here

strsql = "delete from mytable where field1 = 1"
conn.execute strsql

conn.close
set conn = nothing


For deletion of records, make sure you have a WHERE clause. If you do not include a criteria, all records will be deleted from the table.


hongjun
0
 
LVL 8

Expert Comment

by:MYLim
Comment Utility
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:Jangomez74
Comment Utility
Hi lowfatspread, the recordsource for this adodc is "SELECT * FROM transaction_log_basket". Only one table for this ado object.

Guys, I've also tried the SQL-Query that deletes records from a table and it works but another problem arises. When i issue the delete it should finish the delete first before performing the next statement. But what happens is that it performs the next statement even without finishing the delete-SQL. I've used the connection object to execute the query.

I've done some experiment and it seems that if you try to delete more than 3 records using an ado.recordset object, this error occurs.

Guys, thanks for the help. hope you could give me some advice on this.

0
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 50 total points
Comment Utility
>>this fails and give me an error that sez "Key column information is insufficient or incorrect, too many rows were affected by update".

Be sure that your table has a primary key.

>>When i issue the delete it should finish the delete first before performing the next statement. But what happens is that it performs the next statement even without finishing the delete-SQL.

Unless you used the async attribute, it is impossible!
0
 

Author Comment

by:Jangomez74
Comment Utility
Hey emoreau,
thanks, it works...
0
 
LVL 8

Expert Comment

by:MYLim
Comment Utility
amazing Eric...
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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

763 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

6 Experts available now in Live!

Get 1:1 Help Now