Advertisement

05.28.2008 at 07:49AM PDT, ID: 23438222
[x]
Attachment Details

Which is faster / more efficient - ADO Recordset.AddNew ... rs.Update  OR ADO Connection.Execute SQLStatement?

Asked by weiroblpay in VB Database Programming, Visual Basic Programming, SQL Server 2005

Tags: Visual Basic 6

I am using Visual Basic 6.

I would like to know if anyone can tell me which is faster and/or more efficient when adding a new record to a table from another data source.

The Database is SQL server 2005

ADO recordset AddNew / Update OR ADO Command.Execute SQLStatement?

Example:

....
Dim rs as ADODB.Recordset
Dim conn as ADODB.Connection

set conn = new ADODB.Connection
conn.Open myConnectionString
set rs = new ADODB.Recordset
rs.open "SELECT * FROM Cases", conn

rs.AddNew
rs.Fields("ID") = myIDVar
rs.Fields("Name") = myNamevar
rs.Fields("Address") = myAddressvar
rs.Update
..............

OR is this faster?

Dim conn as ADODB.connection
Dim strSQL as String

Set conn = new ADODB.Connection
conn.Open myConnectionString

strSQL = "INSERT INTO Cases(ID, Name, Address) VALUES(" & myIDvar & ", '" & myNamevar & "', '" & myAddressvar & "'")

conn.execute strSQL

......................

The code I'm trying to optimize has many more fields, but this is the gist of it. I populate the variables with the data to be added from another recordset (not shown in code above).

Is there an advantage in speed or performance in either method of adding a new record?

ThanksStart Free Trial
 
 
[+][-]05.28.2008 at 08:08AM PDT, ID: 21661085

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: VB Database Programming, Visual Basic Programming, SQL Server 2005
Tags: Visual Basic 6
Sign Up Now!
Solution Provided By: matrix_aash
Participating Experts: 1
Solution Grade: A
 
 
[+][-]05.28.2008 at 08:27AM PDT, ID: 21661304

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.29.2008 at 11:44AM PDT, ID: 21672084

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628