Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Virtual recordset, then update DB table

Status
Not open for further replies.

wadey

Programmer
Jun 6, 2006
54
GB
i have a virtual ADO recordset. After populating it I then wan't to throw a table name in a db at it, and have it write to the table without cycling through the records or using SQL to update or insert. I know this is possible, but don't know how. Here's the code so far. what do i need to add?

Dim someRS as new ADODB.Recordset
Set someRS = new ADODB.Recordset

someRS.append "Field1", adChar
someRS.append "Field2", adInt

someRS.Open

someRS.AddNew
someRS("Field1") = "something"
someRS("Field2") = 3
someRS.Update

 
Have you tried this?

Code:
'create yoru connection
cn.Open "...."
someRS.ActiveConnection = cn
someRS.UpdateBatch
someRS.Close
cn.Close
 
Thanks, but in your code where do you specify which table to update?
 
Well, that's handled by the fact that the recordset is connected to the tables via its associated connection object.

So, if my recordset's source property is "select * from customers" and my connection's connectionstring property specifies a data source of myDB, then that's how the Update method knows how to update the myDB.Customers table.

I personally avoid the use of the Update and UpdateBatch when possible, preferring to use an SQL based solution. UpdateBatch works well with disconnected recordsets that need to allow for user input and updating of the underlying database.

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top