ADO的问题?该怎么做?!!!(30分)

  • 主题发起人 主题发起人 子龙
  • 开始时间 开始时间

子龙

Unregistered / Unconfirmed
GUEST, unregistred user!
//用ADOQUERY1读取.DBF(有20711条记录),
//把AA.dbf的数据转入INTERBASE库中去

procedure TFupdate.B_okClick(Sender: TObject);
var
i, ll, K :integer;
l :string;
begin
ll:=strtoint(Edit1.Text);
l:=Edit1.Text;
l:=copy(l,3,2);
B_ok.Enabled:=False;
B_exit.Enabled:=False;
Edit1.Enabled:=False;
Label2.Caption:='正在更新'+Edit1.Text+'年往来数据......';
Label2.Visible:=True;
Label2.Refresh;
ProgressBar1.Visible:=True;

for i:=1 to 4 do begin
With DM1.ADOQuery1 do begin
Close;
SQL.Clear;
case i of
1: SQL.Add('Select rq,fphm,yxry as gxry,dhdw as dwmc,pm,ph,'+
'kpsl as sl,dj,yunfei,slf,kpje,jsfs,jsdw,jslx,suie,kxlb '+
'from glyk/cwtz'+l+'.dbf');
2: SQL.Add('Select rq,dhdw as dwmc,yxry as gxry,dzje,jsdw,'+
'jsfs,zy,kxlb from glyk/jedz'+l+'.dbf');
3: SQL.Add('Select rq,dddw as dwmc,ddmc as zy,js,yunfei,'+
'zf,ddje,jsdw,yxry as gxry,kxlb from glyk/ddyf'+l+'.dbf');
4: SQL.Add('Select rq,dwmc,gxry,jsdw,kxlb,jqje from bqye.dbf');
end; //case

try
Open;
except
Close;
showmessage('数据更新失败(1-'+inttostr(i)+')!');
exit;
end; //try
end; //with

//DM1.IBupdate (IBQuery)
with DM1.IBupdate do begin
Close;
SQL.Clear;
case i of
1: SQL.Add('insert into wlfp (rq,fphm,gxry,dwmc,pm,ph,sl,dj,'+
'yunfei,slf,kpje,jsfs,jsdw,jslx,suie,kxlb,czry,wlyear)'+
' values (:rq,:fphm,:gxry,:dwmc,:pm,:ph,:sl,:dj,'+
':yunfei,:slf,:kpje,:jsfs,:jsdw,:jslx,:suie,:kxlb,:czry,:wlyear)');
2: SQL.Add('insert into wldz (rq,dwmc,gxry,dzje,jsdw,jsfs,zy,kxlb,wlyear)'+
' values (:rq,:dwmc,:gxry,:dzje,:jsdw,:jsfs,:zy,:kxlb,:wlyear)');
3: SQL.Add('insert into wlzf (rq,dwmc,zy,js,yunfei,zf,ddje,'+
'jsdw,gxry,kxlb,wlyear) values (:rq,:dwmc,:zy,:js,'+
':yunfei,:zf,:ddje,:jsdw,:gxry,:kxlb,:wlyear)');
4: SQL.Add('insert into wlbqye (rq,dwmc,gxry,jsdw,kxlb,jqje)'+
' values (:rq,:dwmc,:gxry,:jsdw,:kxlb,:jqje)');
end; //case
end; //with


with DM1.IBQuery1 do begin
Close;
SQL.Clear;
case i of
1: SQL.Add('Delete from wlfp where wlyear='+Edit1.Text);
2: SQL.Add('Delete from wldz where wlyear='+Edit1.Text);
3: SQL.Add('Delete from wlzf where wlyear='+Edit1.Text);
4: SQL.Add('Delete from wlbqye');
end; //case
DM1.IBTransaction1.StartTransaction;
try
ExecSQL;
DM1.IBTransaction1.Commit;
Close;
except
DM1.IBTransaction1.Rollback;
Close;
messagebeep(0);
showmessage('删除数据失败(2-'+inttostr(i)+')!');
exit;
end; //try
end; //with


with DM1.ADOQuery1 do begin
K:=0;
while not Eof do begin
DM1.IBupdate.ExecSQL;
DM1.IBupdate.ParamByName('rq').AsDate:=DM1.ADOQuery1.FieldByname('rq').Value;
DM1.IBupdate.ParamByName('dwmc').Value:=DM1.ADOQuery1.FieldByname('dwmc').Value;
DM1.IBupdate.ParamByName('gxry').Value:=DM1.ADOQuery1.FieldByname('gxry').Value;
DM1.IBupdate.ParamByName('kxlb').Value:=DM1.ADOQuery1.FieldByname('kxlb').Value;
DM1.IBupdate.ParamByName('jsdw').Value:=DM1.ADOQuery1.FieldByname('jsdw').Value;
DM1.IBupdate.ParamByName('wlyear').AsSmallInt:=ll;
case i of
1: begin
DM1.IBupdate.ParamByName('fphm').Value:=DM1.ADOQuery1.FieldByname('fphm').Value;
DM1.IBupdate.ParamByName('pm').Value:=DM1.ADOQuery1.FieldByname('pm').Value;
DM1.IBupdate.ParamByName('ph').Value:=DM1.ADOQuery1.FieldByname('ph').Value;
DM1.IBupdate.ParamByName('sl').Value:=DM1.ADOQuery1.FieldByname('sl').Value;
DM1.IBupdate.ParamByName('dj').Value:=DM1.ADOQuery1.FieldByname('dj').Value;
DM1.IBupdate.ParamByName('yunfei').Value:=DM1.ADOQuery1.FieldByname('yunfei').Value;
DM1.IBupdate.ParamByName('slf').Value:=DM1.ADOQuery1.FieldByname('slf').Value;
DM1.IBupdate.ParamByName('kpje').Value:=DM1.ADOQuery1.FieldByname('kpje').Value;
DM1.IBupdate.ParamByName('jsfs').Value:=DM1.ADOQuery1.FieldByname('jsfs').Value;
DM1.IBupdate.ParamByName('jslx').Value:=DM1.ADOQuery1.FieldByname('jslx').Value;
DM1.IBupdate.ParamByName('suie').Value:=DM1.ADOQuery1.FieldByname('suie').Value;
DM1.IBupdate.ParamByName('czry').Value:='';
end; // 1
2: begin
DM1.IBupdate.ParamByName('dzje').Value:=DM1.ADOQuery1.FieldByname('dzje').Value;
DM1.IBupdate.ParamByName('jsfs').Value:=DM1.ADOQuery1.FieldByname('jsfs').Value;
DM1.IBupdate.ParamByName('zy').Value:=DM1.ADOQuery1.FieldByname('zy').Value;
end; // 2
3: begin
DM1.IBupdate.ParamByName('zy').Value:=DM1.ADOQuery1.FieldByname('zy').Value;
DM1.IBupdate.ParamByName('js').Value:=DM1.ADOQuery1.FieldByname('js').Value;
DM1.IBupdate.ParamByName('yunfei').Value:=DM1.ADOQuery1.FieldByname('yunfei').Value;
DM1.IBupdate.ParamByName('zf').Value:=DM1.ADOQuery1.FieldByname('zf').Value;
DM1.IBupdate.ParamByName('ddje').Value:=DM1.ADOQuery1.FieldByname('ddje').Value;
end; // 3
4: DM1.IBupdate.ParamByName('jqje').Value:=DM1.ADOQuery1.FieldByname('jqje').Value;
end; //case


DM1.IBupdate.Close;

// if recno>=5447 then showmessage('1- '+inttostr(recno));

Next; // 到第5549条记录时出错:"提供者或其他服务返回E_FAIL状态"
// 更改ADOQuery1.CursorLocation后到第18332条记录时出错

// if recno>=5447 then showmessage('2- '+inttostr(recno));
end; //while
end; //with
DM1.IBTransaction1.Commit;
end; //for
end;
 
不要贴太多的代码,要说中要害就可以了。我想很少人有耐性看这么长的代码
 
问题解决了
是DBF的问题:yunfei字段 N(6,2),按理说只能输入不大于999.99的数据,
但是用FOXPRO里的REPLACE命令却不同了:REPLACE YUNFEI WITH 10255也成功了,
赋值A=YUNFEI,A就是10255,真奇怪。
 
解決了?那發分吧?呵呵.
其實有問題時不一定要急著貼bbs的,可以先多考慮考慮,這樣不就省下許多分了?
 
这个问题已经解决了,请允许我再问个问题吧:
怎样建触发器(INTERBASE数据库):
当向WLFP中插入记录时,先判断插入的DWMC字段在WLYE表中是否存在,不存在则在WLYE中插入
DWMC
 
先看看创建触发器的语法:

CREATE TRIGGER name FOR table
[ACTIVE | INACTIVE]
{BEFORE | AFTER}
{DELETE | INSERT | UPDATE}
[POSITION number]
AS <trigger_body> terminator

<trigger_body> = [<variable_declaration_list>] <block>
<variable_declaration_list> =
DECLARE VARIABLE variable <datatype>;
[DECLARE VARIABLE variable <datatype>;
<block> =
BEGIN
<compound_statement>
[<compound_statement>
END

<datatype> = SMALLINT
| INTEGER
| FLOAT
| DOUBLE PRECISION
| {DECIMAL | NUMERIC} [(precision [, scale])]
| {DATE | TIME | TIMESTAMP)
| {CHAR | CHARACTER | CHARACTER VARYING | VARCHAR}
[(int)] [CHARACTER SET charname]

| {NCHAR | NATIONAL CHARACTER | NATIONAL CHAR} [VARYING] [(int)]


从上面的语法可以看出,Interbase 的触发器可以跟踪表的下列变化情况:

BEFORE DELETE 在表删除一条记录之前触发
BEFORE INSERT 在表插入一条记录之前触发
BEFORE UPDATE 在表更新一条记录之前触发
AFTER DELETE 在表删除一条记录之后触发
AFTER INSERT 在表插入一条记录之后触发
AFTER UPDATE 在表更新一条记录之后触发

举例如下:

CREATE TRIGGER DELBM FOR FPCSIGNUP
ACTIVE BEFORE DELETE POSITION 0
AS /*
Author : TangHui
Date : 2000-06-28 20:36:22
Email : 3asoft@china.com
*/

BEGIN
/*将数据转入回收站*/
INSERT INTO BM_WASTEBIN
select *
from FPCSIGNUP
where old.SUAUTO=SUAUTO;

update BM_WASTEBIN
SET SUMODIFY=USER,
/*删除人员*/
SUMODIFY_DATE='NOW',
/*删除日期*/
WHERE SUAUTO=old.SUAUTO;
END

上面的例子是在用户删除数据时,将删除的数据放在一个所谓的回收站的表BM_WASTEBIN中。
【注意】在上面的触发器中我们引用了old标识符,除此之外,Interbase还可引用new标识符,它们分别代表记录的当前值和更新前的值。
因此,多逻辑上来判断,在删除记录时,我们不能使用new标识符,而在插入记录时,我们不能使用old标识符。

 
你这个我也有,是抄袭唐辉的资料
 
唐辉是谁。
 
后退
顶部