update or execute?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: update or execute?

  1. #1
    Mike Guest

    update or execute?


    There are a few ways to update records in a database. For example, using rst.Execute
    with a sql statement or manipulating the recordset directly with rst.update.
    Is there a benefit of using one method over the other?
    Share on Google+

  2. #2
    Scott Mitchell Guest

    Re: update or execute?


    Hey there Mike.

    Yes, there are certain times when certain ways are recommended. I find the
    .Update method to be easier to read, especially if the update statement is
    based upon several variables. Most every ASP developer has, at one time
    or another, built up a dynamic SQL string based on form variables or other
    user-inputted information. I think most every one of these developers would
    agree that it's a lot harder to maintain a dynamic SQL string than an Update
    statement. Also, with Update statements, you don't have to worry about replacing
    all single apostrophes with double apostrophes, and other special characters
    that may screw up your SQL string.

    SQL strings are not all bad, though, they do have several advantages. For
    one, SQL strings can affect entire SETS of rows instead of just one row at
    a time. A single update SQL string can be used to alter multiple rows in
    a table whereas the .Update statement can only affect one row at a time...
    (For more information on this, check out: http://www.4guysfromrolla.com/webtech/100199-2.shtml)

    Personally, I stick to SQL strings... despite the readability .Update statements
    offer, I'm very used to using SQL strings, hence my preference for them.
    To a new developer I'd suggest to learn both ways, since projects utilize
    both methods. When creating your projects, use whatever technique you (and
    your other developers) are most comfortable with... just be sure to comment,
    comment, comment, regardless of the method you use!

    Scott Mitchell
    mitchell@4guysfromrolla.com
    http://www.4GuysFromRolla.com
    http://www.ASPMessageBoard.com
    http://www.ASPFAQs.com

    * When you think ASP, think 4GuysFromRolla.com!

    >There are a few ways to update records in a database. For example, using

    rst.Execute
    >with a sql statement or manipulating the recordset directly with rst.update.
    >Is there a benefit of using one method over the other?


    Share on Google+

  3. #3
    mike Guest

    Re: update or execute?


    You can think about the difference in other way. If you are using rs.Update
    then you are reading DB (and probably hard-locking it with fertilizable locks
    if you do not pay attention to cursors and transaction settings), getting
    data to Web Server, updating fields then call Update, that is going back
    to DB server and updating the data (read ADO documentation or any ADO books
    for details). If you are doing dynamic SQL then you are doing only one round-trip
    to DB and you are not holding any locks. That's your performance consideration
    and believe me that you need to think about it if you are doing something
    more then college project.

    The downsides of dynamic SQL approach are difficulties with concurrency management
    and error handling. Your choice.

    "Scott Mitchell" <mitchell@4guysfromrolla.com> wrote:
    >
    >Hey there Mike.
    >
    >Yes, there are certain times when certain ways are recommended. I find

    the
    >.Update method to be easier to read, especially if the update statement

    is
    >based upon several variables. Most every ASP developer has, at one time
    >or another, built up a dynamic SQL string based on form variables or other
    >user-inputted information. I think most every one of these developers would
    >agree that it's a lot harder to maintain a dynamic SQL string than an Update
    >statement. Also, with Update statements, you don't have to worry about

    replacing
    >all single apostrophes with double apostrophes, and other special characters
    >that may screw up your SQL string.
    >
    >SQL strings are not all bad, though, they do have several advantages. For
    >one, SQL strings can affect entire SETS of rows instead of just one row

    at
    >a time. A single update SQL string can be used to alter multiple rows in
    >a table whereas the .Update statement can only affect one row at a time...
    > (For more information on this, check out: http://www.4guysfromrolla.com/webtech/100199-2.shtml)
    >
    >Personally, I stick to SQL strings... despite the readability .Update statements
    >offer, I'm very used to using SQL strings, hence my preference for them.
    > To a new developer I'd suggest to learn both ways, since projects utilize
    >both methods. When creating your projects, use whatever technique you (and
    >your other developers) are most comfortable with... just be sure to comment,
    >comment, comment, regardless of the method you use!
    >
    > Scott Mitchell
    > mitchell@4guysfromrolla.com
    > http://www.4GuysFromRolla.com
    > http://www.ASPMessageBoard.com
    > http://www.ASPFAQs.com
    >
    >* When you think ASP, think 4GuysFromRolla.com!
    >
    >>There are a few ways to update records in a database. For example, using

    >rst.Execute
    >>with a sql statement or manipulating the recordset directly with rst.update.
    >>Is there a benefit of using one method over the other?

    >


    Share on Google+

Similar Threads

  1. Replies: 0
    Last Post: 06-04-2002, 10:13 AM
  2. update query
    By an in forum Database
    Replies: 0
    Last Post: 05-08-2002, 01:12 PM
  3. Replies: 0
    Last Post: 05-07-2002, 08:34 PM
  4. Replies: 1
    Last Post: 10-31-2000, 04:31 AM
  5. Urgent!!! ADO Update conflict
    By Chillu in forum VB Classic
    Replies: 0
    Last Post: 07-14-2000, 12:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center