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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Which is better Add New or Insert ?

Status
Not open for further replies.

Cap2010

Programmer
Mar 29, 2000
196
CA
hi,

Below are two different code. Doing same task.
Which is better to use and effective ?

Code 1
rs.Open sql, Adoconn, adOpenDynamic, adLockOptimistic
rs.AddNew
rs.Fields("ItemCode").Value = "AWI01"
rs.Fields("Name").Value = "ABDEOD"
rs.Fields("DDATE").Value = Date
rs.Update

Code 2
execute.sql(insert.....)

Cap2010
 
The best is to use stored procedures for your data access!

However to answer your question, executesql is faster.

Hope thisis helpful,

VBrit
 
AddNew is an ADO coding style. There is a negligible difference in performance.

However AddNew is at its best when used with this syntax from :
Code:
[b]recordset.AddNew Fields, Values[/b]

[b]Fields[/b] 
This optional parameter specifies a single name or an array of names or ordinal positions of the fields in the new record.
 
[b]Values[/b] 
This optional parameter specifies a single value or an array of values for the fields in the new record. If Fields is an array, Values must also be an array with the same number of members; otherwise, an error occurs. The order of field names must match the order of field values in each array.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top