你先读取第一行,取得d的值,
后面就可以直接用下面的函数
function TfrmCustomer.WbdlDatabase(TbName,FileName:string):Boolean; //导入数据
var
ListString:TStringList;
ListJL:TStringList;
Str,StrSql:string;
i,j:integer;
limitedpos:integer;
begin
screen.Cursor :=crHourGlass;
StrSql := 'select * from '+TbName;
Query_tmp.Close;
Query_tmp.SQL.Clear;
Query_tmp.SQL.Add(StrSql);
Query_tmp.Open;
Result := False;
ListString := TstringList.Create;
ListJL := TStringList.Create;
ListString.LoadFromFile(FileName);
for i:=0 to ListString.Count-1 do
begin
screen.Cursor :=crHourGlass;
Gauge.MinValue :=0;
Gauge.MaxValue :=ListString.Count;
str := ListString.Strings;
ListJL.Clear;
while (Pos(',',Str)>0) or (str<>'') do
begin
limitedpos:=Pos(',',str);
if limitedpos <=0 then
begin
ListJL.Add(str);
Str := '';
end
else
begin
ListJL.Add(Copy(Str,1,limitedpos-1));
Str := Copy(Str,Pos(',',Str)+1,Length(Str));
end;
end;
Query_tmp.Append;
for J :=0 to Query_tmp.FieldCount-1 do
begin
if Query_tmp.Fields[j].DataType =ftAutoInc then Continue;
if Query_tmp.Fields[j].DataType =ftDateTime then
begin
if pos('-',ListJL.Strings[j])>0 then
Query_tmp.Fields[j].AsString :=trim(ListJL.Strings[j])
else
begin
if LIstJL.Strings[j]<>'' then
begin
ListJL.Strings[j] := Copy(ListJL.Strings[j],1,4)+'-'+Copy(ListJL.Strings[j],5,2)+'-'+Copy(ListJL.Strings[j],7,2);
Query_tmp.Fields[j].AsString := trim(ListJL.Strings[j]);
end;
end;
end
else
begin
if Query_tmp.Fields[j].DataType =ftInteger then
begin
Query_tmp.Fields[j].AsInteger :=StrToInt(ListJL.Strings[j]);
end;
if Query_tmp.Fields[j].DataType =ftBoolean then
begin
if (ListJL.Strings[j] ='0') or (ListJL.Strings[j] = 'False') then
Query_tmp.Fields[j].AsBoolean :=False
else
begin
if (ListJL.Strings[j] ='1') or (ListJL.Strings[j] = 'True') then
Query_tmp.Fields[j].AsBoolean := True;
end;
end
else
if ListJL.Strings[j]<>'' then
Query_tmp.Fields[j].AsString := trim(ListJL.Strings[j]);
end;
end;
Query_tmp.Post;
Gauge.Progress :=i+1;
end;
Result := True;
end;