K
ksx
Unregistered / Unconfirmed
GUEST, unregistred user!
在SQL 企业管理器里面检索一个数据表格出现错误提示,运行程序后第一遍能正确提示,按第二遍Btn按钮的时候出现 "连接失败" 的错误提示,请问,我的程序该怎样写?或者控件该怎样配置?程序代码如下不是事务本身的错误,是数据有问题,我就是想在程序遇到有错误的数据库时改怎样写,怎样做出正确的提示)unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, DB, Grids, DBGrids, ADODB, StdCtrls;type TForm1 = class(TForm) Button1: TButton; ADOConnection1: TADOConnection; ADOQuery1: TADOQuery; DBGrid1: TDBGrid; DataSource1: TDataSource; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);beginTryADOConnection1.BeginTrans; with ADOQuery1 Do Begin Close; SQL.Clear; SQL.Add('Select sCstCode as 客户编码,sName as 姓名,sAddr as 地址 from pdocstdir where sName like :aa'); Parameters.ParamByName('aa').Value :='王%'; open; End;ADOConnection1.CommitTrans;ExceptADOConnection1.RollbackTrans;Application.MessageBox('数据库故障,请重新测试','问题',64);end;end;end.