當前位置:編程學習大全網 - 網站源碼 - 在delphi中如何實現用代碼將excel導入到sql數據庫中

在delphi中如何實現用代碼將excel導入到sql數據庫中

nameX := excelapp.Cells[1,1].value; // 讀取EXCEL第壹行的列字段

nameY := excelapp.Cells[1,2].value; // 讀取EXCEL第壹行的列字段

for i := 2 to excelrowcount + 1 do

begin

excelx := excelapp.Cells[i,1].value;

excely := excelapp.Cells[i,2].value;

with query1 do

begin

close;

sql.clear;

sql.add('insert into aa('+nameX+','+nameY+') values(:a,:b)'); // 數據庫裏的字段做成映射

ParamByName('a').value:= excelx;

ParamByName('b').value:= excely;

execsql;

end;

end;

如果是數字, 用strtofloat 或者 strtoint:

ParamByName('b').value:= excely;

改成

ParamByName('b').value:= strtofloat(excely); //excel檔的第二列插入到aa表的 b 欄位;

  • 上一篇:完美視覺源代碼
  • 下一篇:字謎源代碼
  • copyright 2024編程學習大全網