PDA

Click to See Complete Forum and Search --> : question about copying a record


Thai
Mar 13th, 2000, 03:55 AM
Is there a way to copy a record from one table to another with ADO code if the two tables have identical fields? Also, is there an easy way to delete ALL records in a table using ADO code?

Thank you,
Thai

Serge
Mar 13th, 2000, 04:43 AM
1. To copy one record from one table to another, assuming that I know the ID of the record I want to copy. Lets call them Table1 and Table2:

Dim cn As New ADODB.Connection

'Open connection
'Substitute it with appropriate one.
cn.Open "DSN=MyDSN","UserName", "password"
cn.Execute "Insert Table2 Select * From Table1 Where ID = 1"


2. Deleting all records in the table:

Dim cn As New ADODB.Connection

'Open connection
'Substitute it with appropriate one.
cn.Open "DSN=MyDSN","UserName", "password"
cn.Execute "Delete Table1"

Thai
Mar 13th, 2000, 05:43 AM
dim cn as new adodb.connection
cn.execute "Select * From Table1 Where Number = 10"

now.. how do you manipulate those records it just retrieved??

Thanks for the help,
Thai

Clunietp
Mar 13th, 2000, 08:52 AM
You have to return the results of your query to a recordset object:



dim cn as adodb.connection
dim rs as adodb.recordset

set cn = new adodb.connection
set rs = new adodb.recordset

cn.open <connectionstring>

'open recordset, you may then work with it
rs.open "Select * from MyTable", cn, adopenstatic, adlockoptimistic, adcmdtext

'do your stuff here
msgbox rs.fields(0).value