在窗体上放一个StringGrid,Edit1.Edit2想把StringGrid中的数据保存到数据库中,不能出现重复记录,请看下面那段代码,看有什么错误?
Var
pnumb,pname:string; count,result:integer;
begin
pnumb:=trim(edit1.Text);
pname:=trim(edit2.Text);
for count:=1 to stringgrid1.RowCount-1 do
begin
khnumb:=trim(stringgrid1.Cells[1,count]);
hwnumb:=trim(stringgrid1.Cells[2,count]);
datamodule1.T_hwcontr.Active:=true;
if datamodule1.T_hwcontr.Locate('ProNumb;SupClie;HuoWNum;NumSign' VarArrayOf([pnumb,khnumb,hwnumb,nsign]),[]) then
begin
continue;
result:=1;
n:=count;
showmessage('本公司与该客户/厂商的这种产品的对照关系已经存在!') stringgrid1.Cells[2,n]:='';
stringgrid1.Cells[3,n]:='';
stringgrid1.Cells[4,n]:='';
end
else
begin
result:=2;
end;
if result=2 then
begin
with datamodule1.T_hwcontr do
begin
active:=true;
for count:=1 to stringgrid1.RowCount-1 do
begin
append;
fields[0].AsString:=pnumb;
fields[1].AsString:=pname;
fields[2].AsString:=stringgrid1.Cells[1,count];
fields[3].AsString:=stringgrid1.Cells[2,count];
fields[4].AsString:=stringgrid1.Cells[3,count];
fields[6].AsString:=stringgrid1.Cells[4,count];
post;
refresh;
next;
end;
end;
end;}
end;
edit1.Clear;
edit2.Clear;
stringgrid1.RowCount:=2;
stringgrid1.Cells[0,1]:='1';
stringgrid1.Cells[1,1]:='';
stringgrid1.Cells[2,1]:='';
stringgrid1.Cells[3,1]:='';
stringgrid1.Cells[4,1]:='';
end;
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货