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?
Thanks
Start Free Trial