Solved

Deleting Records using an ado.recordset object

Posted on 2003-11-29
8
1,327 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 9842072
Hi Jangomez74,

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

 


Cheers!
0
 
LVL 3

Expert Comment

by:daffyduck14mil
ID: 9842957
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
ID: 9844716
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
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!

 

Author Comment

by:Jangomez74
ID: 9845282
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 70

Accepted Solution

by:
Éric Moreau earned 50 total points
ID: 9845480
>>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
ID: 9848254
Hey emoreau,
thanks, it works...
0
 
LVL 8

Expert Comment

by:MYLim
ID: 9848262
amazing Eric...
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

707 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