如何判断一个数据库更新是成功的? [英] How to tell if a db update was successful?

查看:671
本文介绍了如何判断一个数据库更新是成功的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想修改一些旧式ASP经典code,我不知道很多关于ASP。怎样判断一个数据库插入,更新或删除失败了吗?通过'失败',我的意思是,要么抛出一个错误或受影响零行。

I'm trying to modify some legacy ASP classic code, and I don't know much about ASP. How do I tell if a database Insert, Update, or Delete failed? By 'failed', I mean it either threw an error or affected zero rows.

这里的code,它已经在ASP文件中建立数据库连接:

Here's the code that was already in the ASP file that sets up the database connection:

On Error Resume Next
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "Provider=MSDAORA;Data Source=dbname;User Id=dbuser;Password=dbpw;"

有这工作就像几个Select语句:

There are a few Select statements that work like:

qry =  "select stuff here..."
Set objRs = objConn.Execute(qry)

我知道如何获得从Select语句的结果,但我怎么得到一个非SELECT语句的结果吗?使用结果集似乎并不像它会是这样做的正确方法。或者是什么?

I understand how to get the results from the Select statements, but how do I get the results of a non-Select statement? Using a result set doesn't seem like it'd be the right way to do it. Or is it?

推荐答案

使用第一个执行方法的参数来获得受影响的行:

Use the first Execute method parameter to get the rows affected:

On Error resume next
Dim RecordsAffected as long
Dim cmd
Set cmd = server.createobject("ADODB.Command")

cmd.ActiveConnection = GetConnectionString()
cmd.CommandText = "Select stuff here"
cmd.CommandType = adCmdText

cmd.Execute RecordsAffected, , adExecuteNoRecords
If err.number > 0 or RecordsAffected = 0 then
    Response.Write "No record affected or SQL error or something"
end if

使用 adExecuteNoRecords 将根据的获得性能< A HREF =htt​​p://www.asp101.com/tips/index.asp?id=85>若干的来源

来源:执行在MSDN方法

这篇关于如何判断一个数据库更新是成功的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆