请看代码:
if ADODataSet1.Active then ADODataSet1.Close;
FilesCount:=0;
SelectDirectory('asdfgsasf','',Path);
ChDir(Path);
MakeTree;//在下面
ADODataSet1.CommandText:='SELECT * FROM Files;';
ADODataSet1.Open;
procedure TForm1.MakeTree;
var Sr : TSearchRec;
Err : integer;
FilePath : string;
Begin
Err:=FindFirst('*.*',$37,Sr) ;
While (Err = 0) do
begin
if Sr.Name[1]<>'.' then // 如果不是目录
begin
FilePath:=ExpandFileName(Sr.Name);
if (Sr.Attr and faDirectory)=0 then //and (UpperCase(ExtractFileExt(Sr.Name))='.BMP')
begin
inc(FilesCount);
ADOCommand1.CommandText:='INSERT INTO Files (ID,CD,FileName,Absolutepath) ' +
'VALUES( '+IntToStr(FilesCount)+','+'"CD1"'+','+Sr.Name+','+FilePath+' );';
ADOCommand1.Execute;
end;
end;
If ((Sr.Attr and faDirectory)<>0) and (Sr.Name[1] <> '.') then //如果是目录
begin
inc(FilesCount);
ADOCommand1.CommandText:='INSERT INTO Files (ID,CD,FileName) ' +
'VALUES( '+IntToStr(FilesCount)+','+'"CD1"'+','+FilePath+' );';
ADOCommand1.Execute;
ChDir(ExpandFileName(Sr.Name)) ;
MakeTree ;
ChDir('..') ;
end ;
Err:=FindNext(Sr) ;
end ;
FindClose(Sr);
end;向表中插入记录时报错,Parameter对象定义错误,或者数据不一致,
但我执行:INSERT INTO Files (ID,CD,FileName,Absolutepath) VALUES( 3, "as","sdafg","sdfdg");
是正常,是因为ID字段位数字类型?还是别的原因,其他三个字段为文本类型。
if ADODataSet1.Active then ADODataSet1.Close;
FilesCount:=0;
SelectDirectory('asdfgsasf','',Path);
ChDir(Path);
MakeTree;//在下面
ADODataSet1.CommandText:='SELECT * FROM Files;';
ADODataSet1.Open;
procedure TForm1.MakeTree;
var Sr : TSearchRec;
Err : integer;
FilePath : string;
Begin
Err:=FindFirst('*.*',$37,Sr) ;
While (Err = 0) do
begin
if Sr.Name[1]<>'.' then // 如果不是目录
begin
FilePath:=ExpandFileName(Sr.Name);
if (Sr.Attr and faDirectory)=0 then //and (UpperCase(ExtractFileExt(Sr.Name))='.BMP')
begin
inc(FilesCount);
ADOCommand1.CommandText:='INSERT INTO Files (ID,CD,FileName,Absolutepath) ' +
'VALUES( '+IntToStr(FilesCount)+','+'"CD1"'+','+Sr.Name+','+FilePath+' );';
ADOCommand1.Execute;
end;
end;
If ((Sr.Attr and faDirectory)<>0) and (Sr.Name[1] <> '.') then //如果是目录
begin
inc(FilesCount);
ADOCommand1.CommandText:='INSERT INTO Files (ID,CD,FileName) ' +
'VALUES( '+IntToStr(FilesCount)+','+'"CD1"'+','+FilePath+' );';
ADOCommand1.Execute;
ChDir(ExpandFileName(Sr.Name)) ;
MakeTree ;
ChDir('..') ;
end ;
Err:=FindNext(Sr) ;
end ;
FindClose(Sr);
end;向表中插入记录时报错,Parameter对象定义错误,或者数据不一致,
但我执行:INSERT INTO Files (ID,CD,FileName,Absolutepath) VALUES( 3, "as","sdafg","sdfdg");
是正常,是因为ID字段位数字类型?还是别的原因,其他三个字段为文本类型。
ADOCommand1.CommandText:='INSERT INTO Files (ID,CD,FileName) ' +
'VALUES( '+IntToStr(FilesCount)+','+'"CD1"'+','+FilePath+' );';
改为:
ADOCommand1.CommandText:='INSERT INTO Files (ID,CD,FileName,Absolutepath) ' +
'VALUES( '+IntToStr(i)+','+'"CD1"'+','+'"'+ExtractFileName(StrList[i])+'"'+','+'"'+StrList[i]+'"'+' );';