procedure Tloca.Button1Click(Sender: TObject);
begin
if Trim(Edit1.Text)='' then
application.MessageBox('请输入要新增的库位名!','提示',mb_ok+mb_iconinformation)
else
begin
dm.ADOQuery1.Close;
dm.ADOQuery1.SQL.Clear;
dm.ADOQuery1.SQL.Add('Select location from Exe_loca where location='''+Trim(Edit1.Text)+'''');
try
dm.ADOQuery1.Open;
except
dm.ADOQuery1.ExecSQL;
end;
if not dm.ADOQuery1.Eof then
application.MessageBox('该库位已存在!','提示',mb_ok+mb_iconinformation)
else
begin
dm.ADOQuery1.Close;
dm.ADOQuery1.SQL.Clear;
dm.ADOQuery1.SQL.Add('Insert into Exe_loca (location,putawayzone,ifmix) values('''+trim(edit1.Text)+''','''+trim(edit2.Text)+''','''+trim(combobox1.Text)+''')');
dm.ADOQuery1.ExecSQL;
end
end
end;
begin
if Trim(Edit1.Text)='' then
application.MessageBox('请输入要新增的库位名!','提示',mb_ok+mb_iconinformation)
else
begin
dm.ADOQuery1.Close;
dm.ADOQuery1.SQL.Clear;
dm.ADOQuery1.SQL.Add('Select location from Exe_loca where location='''+Trim(Edit1.Text)+'''');
try
dm.ADOQuery1.Open;
except
dm.ADOQuery1.ExecSQL;
end;
if not dm.ADOQuery1.Eof then
application.MessageBox('该库位已存在!','提示',mb_ok+mb_iconinformation)
else
begin
dm.ADOQuery1.Close;
dm.ADOQuery1.SQL.Clear;
dm.ADOQuery1.SQL.Add('Insert into Exe_loca (location,putawayzone,ifmix) values('''+trim(edit1.Text)+''','''+trim(edit2.Text)+''','''+trim(combobox1.Text)+''')');
dm.ADOQuery1.ExecSQL;
end
end
end;
dm.ADOQuery1.Open;
except
dm.ADOQuery1.ExecSQL;
---------------
改为 dm.ADOQuery1.Open;
再就是你不循環,怎麼可能插入多條記錄?
procedure Tloca.Button1Click(Sender: TObject);
begin
if Trim(Edit1.Text)='' then
application.MessageBox('请输入要新增的库位名!','提示',mb_ok+mb_iconinformation)
else
begin
dm.ADOQuery1.Close;
dm.ADOQuery1.SQL.Clear;
dm.ADOQuery1.SQL.Add('Select location from Exe_loca where location='+QuotedStr(Trim(Edit1.Text));
dm.ADOQuery1.Open;
if dm.ADOQuery1.recordcount<>0 then
application.MessageBox('该库位已存在!','提示',mb_ok+mb_iconinformation)
else
begin
dm.ADOQuery1.Close;
dm.ADOQuery1.SQL.Clear;
dm.ADOQuery1.SQL.Add('Insert into Exe_loca (location,putawayzone,ifmix) values('''+trim(edit1.Text)+''','''+trim(edit2.Text)+''','''+trim(combobox1.Text)+''')');
dm.ADOQuery1.ExecSQL;
end
end
end;
如果还是不行的话,就要看看'Select location from Exe_loca where location='+QuotedStr(Trim(Edit1.Text));这句话了,是不是真正能够找出已经存在的那条记录
dm.ADOQuery1.sql.clear;
dm.ADOQuery1.sql.add('delete from 表1 where 字段<>1');
try
dm.ADOQuery1.ExecSQL;
ShowMessage('记录已经删除');
except
on e:exception do
ShowMessage(e.message);
end;
不过对于这种不返回数据集的操作我一般会使用TADOCOMMAND组件,这个要好的多。