关于触发器的一个问题(sql server 2000)(50分)

  • 主题发起人 主题发起人 sun_hong_jun
  • 开始时间 开始时间
S

sun_hong_jun

Unregistered / Unconfirmed
GUEST, unregistred user!
本人想测验一下存储过程的效果,举了一个例子如下“
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, DBCtrls, StdCtrls, DB, Grids, DBGrids, DBTables;

type
TForm1 = class(TForm)
Query: TQuery;
DBGrid1: TDBGrid;
DataSource1: TDataSource;
Button1: TButton;
DBNavigator1: TDBNavigator;
Table1: TTable;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
dbgrid1.EditorMode :=true;
with query do
begin
close;
with sql do
begin
clear;
add('update products set supplierid=3');
end;
prepare;
open;
end;

end;

end
且关于products表的触发器定义如下:.
create trigger tr_product_update on products
for update
as
declare @msg varchar(100)
set @msg=str(@@rowcount)+'employees updated by this statement'
print @msg
go
运行以后,出现错误提示:'error create cursor handle',为什么?

 
procedure TForm1.Button1Click(Sender: TObject);
begin
dbgrid1.EditorMode :=true;
with query do
begin
close;
with sql do
begin
clear;
add('update products set supplierid=3');
end;
prepare;
////////////////////////////////////////////////////////////////////////
// open; 改为:
ExecSQL;
////////////////////////////////////////////////////////////////////////
end;

end;

 
记住一点,除了Select语句用Open方法,其他都用ExecSql方法,以后就不会犯同样的错了
 
后退
顶部