用adoquery,做sql查询
delete from table where 区号=:qh
可是在程序执行时提示“无返回值。“,然后中断,必须再次运行。
该如何阻止它弹出异常对话框????
delete from table where 区号=:qh
可是在程序执行时提示“无返回值。“,然后中断,必须再次运行。
该如何阻止它弹出异常对话框????
解决方案 »
- delphi中如何设置半角方式的中文输入法
- 请介绍一个带树型的下拉控键!
- 怎样执行Windows命令?在线等待……
- D6下数据别名的问题
- Ehlib的TDBEditEh ReadOnly Bug如何修改?.txt
- 怎么对网页进行分析,如只取出一部分表格中的文字?
- MonthCalendar在delphi5中有这个控件么?我找不到啊。
- 如何实现最小化?
- shr 是什么意思?
- 我想问问,如何在windows关机之前截获消息(先不关)然后运行我的软件,然后再发出消息,关机
- 线程问题。急!来者有分!
- 询问 delphi 7.0 Enterprise 的市场价格,各位不吝赐教,bigysw(大花脸)谢过!
adoquery.ExecSQL
except
end
DataModule1.ADOQuery_fw.SQL.Clear;
DataModule1.ADOQuery_fw.Parameters.Items[0].Value:=MEdit_qzh.Text;
DataModule1.ADOQuery_fw.SQL.Add('delete from unit_house where 区座号=:qzh');
DataModule1.ADOQuery_fw.ExecSQL;
我用的是sql server 2000,运行后错误消息如下::
project P_mainfrm.exe raised exception class ElistError with message
'list index out of bounds(0)'.Process stopped救我丫!!!
由于这种命令不返回数据
这样就会清空数据集
我觉得使用这种命令时使用一个新的adoquery或者是命令对象单独执行
然后再刷新数据源就可以了
而且都没有连接数据源,只有DBGrid连接了数据源。
每个控件都是过了,还是project P_mainfrm.exe raised exception class ElistError with message
'list index out of bounds(0)'.Process stopped
A complete listing of the database errorcodes is found in the
DBIErrs.Int file in the Delphi/Doc directory or in the IDAPI.h
file in the Borland Database Engine. Database errors are defined by category and code. Here's a sample:{ ERRCAT_INTEGRITY } ERRCODE_KEYVIOL = 1; { Key violation }
ERRCODE_MINVALERR = 2; { Min val check failed }
ERRCODE_MAXVALERR = 3; { Max val check failed }
ERRCODE_REQDERR = 4; { Field value required }
ERRCODE_FORIEGNKEYERR = 5; { Master record missing }
ERRCODE_DETAILRECORDSEXIST = 6; { Cannot MODIFY or DELETE this Master record }
ERRCODE_MASTERTBLLEVEL = 7; { Master Table Level is incorrect }
ERRCODE_LOOKUPTABLEERR = 8; { Field value out of lookup tbl range }
ERRCODE_LOOKUPTBLOPENERR = 9; { Lookup Table Open failed }
ERRCODE_DETAILTBLOPENERR = 10; { 0x0a Detail Table Open failed }
ERRCODE_MASTERTBLOPENERR = 11; { 0x0b Master Table Open failed }
ERRCODE_FIELDISBLANK = 12; { 0x0c Field is blank }
The constant for the base category is added to these constants to represent
a unique DBI errorcode; DBIERR_KEYVIOL = (ERRBASE_INTEGRITY + ERRCODE_KEYVIOL);
DBIERR_REQDERR = (ERRBASE_INTEGRITY + ERRCODE_REQDERR);
DBIERR_DETAILRECORDSEXIST = (ERRBASE_INTEGRITY + ERRCODE_DETAILRECORDSEXIST);
DBIERR_FORIEGNKEYERR = (ERRBASE_INTEGRITY + ERRCODE_FORIEGNKEYERR); The ERRBASE_INTEGRITY value is $2600 (Hex 2600) or 9728 decimal.
Thus, for example, the errorcode for keyviol is 9729
for master with details is 9734.
开头加上:
const
eKeyViol = 9729;
eRequiredFieldMissing = 9732;
eForeignKey = 9733;
eDetailsExist = 9734;implementation1、主从表删主表(无级联删除情况)
procedure Tdatamodule1.table1DeleteError(Dataset:Tdataset;E:EDatabaseError;var Action:TdataAction);
begin
if (E is EDBEngineError) then
if (E as EDBEngineError).Error[0].Errorcode=eDetailsExist then
begin
messageDLG('请先删除从表的相关的记录!',mtWarning,[mbOK],0);
abort;
end;
end;
2、主关键字重复
procedure Tdatamodule1.table1PostError(Dataset:Tdataset;E:EDatabaseError;var Action:TdataAction);
begin
if (E is EDBEngineError) then
if (E as EDBEngineError).Error[0].Errorcode=eKeyViol then
begin
messageDLG('主关键字重复!已经存在该编号!',mtWarning,[mbOK],0);
abort;
end;
end;
3、关键字重复和关键字为空的情况
procedure Tdatamodule1.table1PostError(Dataset:Tdataset;E:EDatabaseError;var Action:TdataAction);
var Error:integer;
begin
if (E is EDBEngineError) then
begin
Error:= (E as EDBEngineError).Errors[0].Errorcode;
case Error of
eRequiredFieldMissing: //关键字为空
begin
messageDLG('主关键字不能为空!',mtWarning,[mbOK],0);
Abort;
end;
eKeyViol: //关键字已经存在
begin
messageDLG('主关键字重复!已经存在该编号!',mtWarning,[mbOK],0);
Abort;
end;
end;
end;
end;beforepost过程中的验证:
table1.fieldbyname('name').focuscontrol;
raise Exception.create(table1.fieldbyname('name').displaylabel+'错误');
一个是主的用于连接数据源,向用户提供数据
另一个辅助,专门执行那些没有返回的命令,这个是不用连接数据源的
这样的好处就是数据显示不会断,比如你就使用主ado执行没有返回的命令
那么数据控件中的对象是要清空的,你还得再次执行来显示数据
辅助的用execsql
adoquery.ExecSQL
except
end
DataModule1.ADOQuery_fw.SQL.Clear;
DataModule1.ADOQuery_fw.Parameters.Items[0].Value:=MEdit_qzh.Text;//出错是这这行此时没有Parameters.Items[0]
DataModule1.ADOQuery_fw.SQL.Add('delete from unit_house where 区座号=:qzh');
DataModule1.ADOQuery_fw.Parameters.Items[0].Value:=MEdit_qzh.Text;//应放在这里!
DataModule1.ADOQuery_fw.ExecSQL;
还有个问题:做了删除delete后,我的DBGrid中的数据不能显示删除后的数据表!
我该如个刷新呢???