procedure TForm3.BitBtn2Click(Sender: TObject);用SQL操作比较灵活.你看看下面的
var
i:Integer;
begin //厂商资料表
OpenDialog1.Title := '请选择相应的Excel文件';
OpenDialog1.Filter := 'Excel(*.xls)|*.xls';
try
begin
if OpenDialog1.Execute then
MyExcelFile :=OpenDialog1.FileName;
ADOConnection1.Close;
ADOConnection1.ConnectionString :='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+MyExcelFile+';Extended Properties=excel 8.0;Persist Security Info=False';
ADOConnection1.Connected :=true;
adoquery1.Close;
ADOQuery1.SQL.Clear;
adoquery1.SQL.Add( 'SELECT * FROM [sheet1$]');
adoquery1.Open;
ProgressBar1.Max := ADOQuery1.RecordCount;
Label2.Caption:='0';
Label4.Caption:='0';
BitBtn1.Enabled:=False;
BitBtn2.Enabled:=False;
for i:=1 to ADOQuery1.RecordCount do
begin
Application.ProcessMessages;
self.refresh;
ADOQuery2.Close;
ADOQuery2.ConnectionString:=constring;
ADOQuery2.SQL.Clear;
ADOQuery2.SQL.Add('select csbh from changshang where csbh='+QuotedStr(Trim(ADOQuery1.fieldbyName('供应商').AsString)));
ADOQuery2.Open;
if ADOQuery2.FieldByName('csbh').AsString='' then
begin
Label2.Caption:=IntToStr(StrTOint(Label2.caption)+1);
// ShowMessage(IntToStr(ADOQuery2.RecordCount));
ADOQuery2.Close;
ADOQuery2.SQL.Clear; // 1 2 3 4 5 6 7 8 9 10 11 12 13 14
ADOQuery2.SQL.Add('insert into changshang(csbh,csmc,lxr,dz,csdh1,csdh2,csdh3,cz,sj,dzyx,wz,yhzh,khyh,bz)'); //