標籤:images error ade from message fromfile 開啟檔案 複製 count
從記事本裡匯入工資資料到資料庫的寫法,
這種需要用的opendialog 要先添加這個組件;
1 procedure TForm3.N6Click(Sender: TObject); 2 var 3 KeFuAry: TArray<string>; 4 YueFen: string; 5 MyList: TStringList; 6 MyAdoq: TADOQuery; 7 I: Integer; 8 begin 9 MyList := TStringList.Create;10 MyAdoq := TADOQuery.Create(nil);11 try12 MyAdoq.Connection := frmDataPool.ADOConnection1;13 //擷取月份14 if not InputQuery(‘輸入月份‘, ‘輸入月份‘, YueFen) then15 begin16 ShowMessage(‘請輸入月份‘);17 Exit;18 end;19 //從剪下板取到資料20 try21 if OpenDialog1.Execute then22 begin23 MyList.Clear;24 MyList.LoadFromFile(OpenDialog1.FileName);25 end;26 except27 on E:EReadError do28 ShowMessage(‘開啟檔案失敗‘);29 end;30 31 //取出空值逐行讀取32 for I := 0 to MyList.Count - 1 do33 begin34 if (MyList[I] <> ‘‘) and (MyList[I] <> ‘工資匯總:‘) then35 begin36 KeFuAry := MyList[I].Replace(‘:‘, ‘,‘).Replace(‘(‘, ‘‘).Replace(‘)‘, ‘‘).Replace(‘基本工資‘, ‘‘).Replace(‘- 個人社保‘, ‘,‘).Replace(‘- 個人公積金‘,‘,‘).37 Replace(‘+ 加班請假‘, ‘,‘).Replace(‘+ 銷售提成‘, ‘,‘).Replace(‘+ 銷售獎金‘,‘,‘).Replace(‘+ 積分獎金‘, ‘,‘).Replace(‘+ QQ群獎金‘, ‘,‘).38 Replace(‘= ‘,‘,‘).Replace(‘ 元‘,‘‘).Split([‘,‘]);39 40 //寫入資料庫41 with MyAdoq do42 begin43 Close;44 SQL.Text := ‘INSERT INTO 工資表(月份,姓名,基本工資,個人社保代繳,個人公積金代繳,加班請假,銷售提成,銷售獎金,售後積分獎金,QQ群等級獎金,工資總額) VALUES (‘+YueFen.QuotedString+‘,‘+KeFuAry[0].QuotedString+‘,‘+45 KeFuAry[1]+‘,-‘+KeFuAry[2]+‘,-‘+KeFuAry[3]+‘,‘+KeFuAry[4]+‘,‘+KeFuAry[5]+‘,‘+46 KeFuAry[6]+‘,‘+KeFuAry[7]+‘,‘+KeFuAry[8]+‘,‘+KeFuAry[9]+‘)‘;47 ExecSQL;48 end;49 end;50 51 //防止程式假死52 Application.ProcessMessages;53 end;54 55 //重新整理下顯示56 frmDataPool.qry工資表.Close;57 frmDataPool.qry工資表.Open;58 finally59 MyList.Free;60 MyAdoq.Free;61 end;62 end;
從記事本裡匯入工資資料到資料庫的寫法