Solved

Deleting Records using an ado.recordset object

Posted on 2003-11-29
8
1,313 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
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
 
LVL 8

Expert Comment

by:MYLim
ID: 9844896
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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 69

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

919 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

18 Experts available now in Live!

Get 1:1 Help Now