怎样知道sql操作是否成功(100分)

  • 主题发起人 主题发起人 wyw1
  • 开始时间 开始时间
W

wyw1

Unregistered / Unconfirmed
GUEST, unregistred user!
我要query进行数据库的操作,主要是update和delete
但是我怎样知道update是否成功呢,我当然可以操作完了后再查一下
但是太烦了,我的意思是说query里面有没有什么属性表示操作的成
功与否,或是其他的简便方法
 
只要没有异常发生,就表示成功了.
 
试试
RowsAffected:

nspect RowsAffected to determine how many rows were updated or deleted by the last query operation. If no rows were updated or deleted, RowsAffected has a value of zero. RowsAffected will have a value of ? if the execution of the SQL statement could not be executed due to an error condition. This latter situation would typically follow the raising of an exception.
 
我已经在Oracle8i下测试成功,如果sql操作是否成功,返回实际的记录数。如果出
错,返回不确定,但是发生异常。

试试
RowsAffected:

nspect RowsAffected to determine how many rows were updated
or deleted by the last query operation. If no rows were updated
or deleted, RowsAffected has a value of zero. RowsAffected will
have a value of ? if the execution of the SQL statement could
not be executed due to an error condition. This latter situation
would typically follow the raising of an exception.


 
前卫兄:

如果没有用 try...except... 出了错误的话 你那句没办法执行到他,就没用了,
要是能执行你那句,又说明没有错误,你那句放上去是多此一举了

要是有 try...except... 那就也不用你那句就很容易判断了
 
如果返回0呢,不发生异常,但有可能是用户输错数据呢?所以,对那中一定要执行
成功还有有用的!
 
0 正常
100 没有数据
-1 错误
 
用SQl Monitor看看就知道了。
 
看返回值。
 
Error: Boolean;
Error:=False;
try
Query1.Open
except
Error:=True
end;
 
用户输入数据肯定要事先校验,保证数据是正确的.
再用try...execept语句....
 
接受答案了.
 
后退
顶部