[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Deleting Records using an ado.recordset object

Posted on 2003-11-29
8
Medium Priority
?
1,332 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
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.

 

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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
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…
Suggested Courses

650 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