How to know if UPDATE, INSERT or DELETE succeed

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default How to know if UPDATE, INSERT or DELETE succeed

    Hi,

    Suppose that, "Set Rs = cmd.Execute" perform a DELETE command. How
    can'I check if the command succeed without to requery the table seeking
    for the involved record?

    Rs.GetRows result in an error message like ' cannot operate on a closed
    object
    Where is the number of DELETE, UPDATED or INSERTED record?

    thank's in advance
    serge

    Serge Myrand Guest

  2. Similar Questions and Discussions

    1. I need a View, Insert, Update, Delete paradigm for usingflash forms
      Flash forms are the greatest. But I'm struggling with a usable paradigm for handling all database functions with them. Most notably, since I can't...
    2. ASP/VBS Using Command to Insert/Update/Delete
      Hi, I would just like to know when/why etc would you command and if there any penalties in using the command. Thanks, Sanjay
    3. SQL Update, Insert and Delete
      Why do I get the message "Operation must use an updateable query" on an Update, Insert and Delete. Mind you the site worked fine before a recent...
    4. OOP page: Where to put update, insert, delete
      I have a page that shows info from MySQL. It is for an online education site. It uses different classes arranged in a hierarchy. Each lesson is...
    5. Before update or delete trigger to insert ?
      Hi, I need some help...I'm fairly new to triggers and am attempting to duplicate a trigger in DB2 that already works in SQL Server. The basics...
  3. #2

    Default Re: How to know if UPDATE, INSERT or DELETE succeed

    Hi,

    Here is what I did. It works find for all commands DELETE, UPDATE and INSERT.
    The following is the DELETE routine. I use Access 2000 with ADO 2.7 and JET
    4.0 sp8 . I put all the SQL in my ASP files. I just want to know how to get
    the result of the command. thank's

    sub DeleteBasketItems
    dim Conn
    dim Cmd
    dim Rs
    dim sSQL
    dim prm
    sSQL = "DELETE * FROM BASKET " & _
    "WHERE CLIENT_NO=? AND BASKET_NO = 0"
    set conn = Server.CreateObject("ADODB.Connection")
    conn.ConnectionString="Provider=Microsoft.Jet.OLED B.4.0;Data Source=" & _
    Server.MapPath("Data\WEB_PROD.mdb") & ";Persist Security
    Info=True"
    conn.CursorLocation = adUseClient
    conn.Open
    set cmd= Server.CreateObject("ADODB.Command")
    Set cmd.ActiveConnection = Conn
    cmd.CommandText = sSQL
    cmd.CommandType = adCmdText
    set prm = cmd.CreateParameter("@prmCustNo", adChar, adParamInput, 13)
    cmd.Parameters.Append prm
    cmd.Parameters("@prmCustNo").Value = Session("ClientNo")
    Set Rs = cmd.Execute
    end sub

    "Aaron [SQL Server MVP]" wrote:
    > > Suppose that, "Set Rs = cmd.Execute" perform a DELETE command.
    >
    > Why on earth would you use a recordset for that?
    >
    > > How
    > > can'I check if the command succeed without to requery the table seeking
    > > for the involved record?
    >
    > If you are using SQL Server (you forgot to tell us what product you're
    > using), you can use a stored procedure to perform the delete, then check
    > @@ROWCOUNT.
    >
    > You should NOT be looping through a recordset object to perform updates or
    > deletes.
    >
    > --
    > [url]http://www.aspfaq.com/[/url]
    > (Reverse address to reply.)
    Serge Myrand Guest

  4. #3

    Default Re: How to know if UPDATE, INSERT or DELETE succeed

    > Suppose that, "Set Rs = cmd.Execute" perform a DELETE command.

    Why on earth would you use a recordset for that?
    > How
    > can'I check if the command succeed without to requery the table seeking
    > for the involved record?
    If you are using SQL Server (you forgot to tell us what product you're
    using), you can use a stored procedure to perform the delete, then check
    @@ROWCOUNT.

    You should NOT be looping through a recordset object to perform updates or
    deletes.

    --
    [url]http://www.aspfaq.com/[/url]
    (Reverse address to reply.)


    Aaron [SQL Server MVP] Guest

  5. #4

    Default Re: How to know if UPDATE, INSERT or DELETE succeed

    Thank you very much, I am learning all this stuff and you guys are very kinds
    and helpfull. It's a big change in language for me.

    serge

    "Bob Barrows [MVP]" wrote:
    > Serge Myrand wrote:
    > > Hi,
    > >
    > > Here is what I did. It works find for all commands DELETE, UPDATE and
    > > INSERT.
    > <snip>
    > > Set Rs = cmd.Execute
    >
    > And here is what you should have done:
    >
    > dim lRecs
    > cmd.Execute lRecs,,128
    > Response.Write lRecs & " records were affected by this query"
    >
    > As Aaron said, it is very wasteful of resources to create a recordset when
    > the query you are running is not intended to return records.
    >
    > The "128" argument (adExecuteNoRecords) tells the Command object not to
    > build a recordset object behind the scenes when the Execute command is,
    > well, er, executed. :-)
    >
    > HTH,
    > Bob Barrows
    > --
    > Microsoft MVP -- ASP/ASP.NET
    > Please reply to the newsgroup. The email account listed in my From
    > header is my spam trap, so I don't check it very often. You will get a
    > quicker response by posting to the newsgroup.
    Serge Myrand Guest

  6. #5

    Default Re: How to know if UPDATE, INSERT or DELETE succeed

    Serge Myrand wrote:
    > Hi,
    >
    > Here is what I did. It works find for all commands DELETE, UPDATE and
    > INSERT.
    <snip>
    > Set Rs = cmd.Execute
    And here is what you should have done:

    dim lRecs
    cmd.Execute lRecs,,128
    Response.Write lRecs & " records were affected by this query"

    As Aaron said, it is very wasteful of resources to create a recordset when
    the query you are running is not intended to return records.

    The "128" argument (adExecuteNoRecords) tells the Command object not to
    build a recordset object behind the scenes when the Execute command is,
    well, er, executed. :-)

    HTH,
    Bob Barrows
    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.


    Bob Barrows [MVP] Guest

  7. #6

    Default Re: How to know if UPDATE, INSERT or DELETE succeed

    I might be mistaken, but is it safe to say that if an error is NOT
    thrown, the command succeeded?

    David H

    Serge Myrand wrote:
    > Hi,
    >
    > Suppose that, "Set Rs = cmd.Execute" perform a DELETE command. How
    > can'I check if the command succeed without to requery the table seeking
    > for the involved record?
    >
    > Rs.GetRows result in an error message like ' cannot operate on a closed
    > object
    > Where is the number of DELETE, UPDATED or INSERTED record?
    >
    > thank's in advance
    > serge
    >
    David C. Holley Guest

  8. #7

    Default Re: How to know if UPDATE, INSERT or DELETE succeed

    No.
    If no records match the criteria provided for the operation, the operation
    will not throw an error, but the operation will not affect any records.

    Bob Barrows

    David C. Holley wrote:
    > I might be mistaken, but is it safe to say that if an error is NOT
    > thrown, the command succeeded?
    >
    > David H
    >
    > Serge Myrand wrote:
    >> Hi,
    >>
    >> Suppose that, "Set Rs = cmd.Execute" perform a DELETE command. How
    >> can'I check if the command succeed without to requery the table
    >> seeking for the involved record?
    >>
    >> Rs.GetRows result in an error message like ' cannot operate on a
    >> closed object
    >> Where is the number of DELETE, UPDATED or INSERTED record?
    >>
    >> thank's in advance
    >> serge
    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"


    Bob Barrows [MVP] Guest

  9. #8

    Default Re: How to know if UPDATE, INSERT or DELETE succeed

    >I might be mistaken, but is it safe to say that if an error is NOT thrown,
    >the command succeeded?
    For an INSERT, probably. For the others, it really depends on how you
    define "succeeded". Consider these statements:

    UPDATE tbl SET col='blat' WHERE 1 = 2

    DELETE tbl WHERE 1 = 2

    INSERT tbl2(col) SELECT col FROM tbl1 WHERE 1 = 2

    None of these statements generated an error, but none of them affected any
    rows, either.

    A


    Aaron [SQL Server MVP] Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139