ADOQuery1.ExecSQL与ADOQuery1.Open有什么区别?还有以下代码有什么问题,为什么一运行到ADOQuery1.ExecSQl就出现:Project raised exception class EAccessViolation with message 'Access Violation at address 1F453E7E in module 'msado15.dll'.write of address 015A9000'.Process stopped.错误提示。
代码如下:
procedure TForm1.N1Click(Sender: TObject);
var SrChannel,srFile : TSearchRec;
Err,Err2 : integer;
ChannelPath : string;
AdoTableFiles:TADOTable;
//将VideoRoot目录下的文件导入vod.mdb中的table files中
Begin
//删除原来的记录
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('delete from files');
ADOQuery1.ExecSQL;
ADOQuery1.Close; AdoTableFiles:= TADOTable.Create(Form1);
AdoTableFiles.Connection:=ADOConnection1;
AdoTableFiles.TableName:='files';
AdoTableFiles.active:=true; Err:=FindFirst(VideoRoot+'\*.*',faDirectory ,SrChannel) ;
While (Err = 0) do
begin
//读出一个频道名
if SrChannel.Name[1]<>'.' then
begin
ChannelPath:=VideoRoot+'\'+SrChannel.Name;
// 读出该频道下的所有文件
Err2:= FindFirst(ChannelPath+'\*.*', faAnyFile ,SrFile);
While (Err2 = 0) do
begin
If ((SrFile.Attr and faDirectory)=0) then
begin
AdoTableFiles.Insert;
AdoTableFiles.FieldByName('频道').AsString:= SrChannel.Name;
AdoTableFiles.FieldByName('文件').AsString:= SrFile.Name;
AdoTableFiles.FieldByName('节目').AsString:= SrFile.Name;
AdoTableFiles.FieldByName('大小').AsInteger:= SrFile.size;
AdoTableFiles.Post;
end;
Err2:=FindNext(SrFile) ;
end;
FindClose(SrFile);
end; Err:=FindNext(SrChannel) ;
end ;
FindClose(SrChannel); AdoTableFiles.Close;
AdoTableFiles.free; //从files 导入 programs ,channels
with ADOQuery1 do
begin
SQL.Clear;
SQL.Add('delete from channels ');
ExecSQL;
Close; SQL.Clear;
SQL.Add('insert into channels (频道) select distinct 频道 from files ');
ExecSQL;
Close; SQL.Clear;
SQL.Add('DELETE FROM programs WHERE 频道+''\''+文件 not in (select 频道+''\''+文件 from files)');
ExecSQL;
Close; SQL.Clear;
SQL.Add('INSERT INTO programs(节目,频道, 文件, 大小) '+
' SELECT files.节目, files.频道, files.文件, files.大小 '+ ' FROM files LEFT JOIN programs ON ((files.文件 = programs.文件) and (files.频道 = programs.频道))'+ ' WHERE (((programs.文件) Is Null) and ((programs.频道) Is Null)) ');
ExecSQL;
Close;
end ;
ADOConnection1.Close;
ADOConnection1.open;
if (not ADOConnection1.Connected) then ADOConnection1.Connected:=True;
AdoTablePrograms.Active:=true;
ImportChannel;
ADOTablePrograms.Refresh;
CreateMediaList;
TabSheetProgram.Show;
end;
代码如下:
procedure TForm1.N1Click(Sender: TObject);
var SrChannel,srFile : TSearchRec;
Err,Err2 : integer;
ChannelPath : string;
AdoTableFiles:TADOTable;
//将VideoRoot目录下的文件导入vod.mdb中的table files中
Begin
//删除原来的记录
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('delete from files');
ADOQuery1.ExecSQL;
ADOQuery1.Close; AdoTableFiles:= TADOTable.Create(Form1);
AdoTableFiles.Connection:=ADOConnection1;
AdoTableFiles.TableName:='files';
AdoTableFiles.active:=true; Err:=FindFirst(VideoRoot+'\*.*',faDirectory ,SrChannel) ;
While (Err = 0) do
begin
//读出一个频道名
if SrChannel.Name[1]<>'.' then
begin
ChannelPath:=VideoRoot+'\'+SrChannel.Name;
// 读出该频道下的所有文件
Err2:= FindFirst(ChannelPath+'\*.*', faAnyFile ,SrFile);
While (Err2 = 0) do
begin
If ((SrFile.Attr and faDirectory)=0) then
begin
AdoTableFiles.Insert;
AdoTableFiles.FieldByName('频道').AsString:= SrChannel.Name;
AdoTableFiles.FieldByName('文件').AsString:= SrFile.Name;
AdoTableFiles.FieldByName('节目').AsString:= SrFile.Name;
AdoTableFiles.FieldByName('大小').AsInteger:= SrFile.size;
AdoTableFiles.Post;
end;
Err2:=FindNext(SrFile) ;
end;
FindClose(SrFile);
end; Err:=FindNext(SrChannel) ;
end ;
FindClose(SrChannel); AdoTableFiles.Close;
AdoTableFiles.free; //从files 导入 programs ,channels
with ADOQuery1 do
begin
SQL.Clear;
SQL.Add('delete from channels ');
ExecSQL;
Close; SQL.Clear;
SQL.Add('insert into channels (频道) select distinct 频道 from files ');
ExecSQL;
Close; SQL.Clear;
SQL.Add('DELETE FROM programs WHERE 频道+''\''+文件 not in (select 频道+''\''+文件 from files)');
ExecSQL;
Close; SQL.Clear;
SQL.Add('INSERT INTO programs(节目,频道, 文件, 大小) '+
' SELECT files.节目, files.频道, files.文件, files.大小 '+ ' FROM files LEFT JOIN programs ON ((files.文件 = programs.文件) and (files.频道 = programs.频道))'+ ' WHERE (((programs.文件) Is Null) and ((programs.频道) Is Null)) ');
ExecSQL;
Close;
end ;
ADOConnection1.Close;
ADOConnection1.open;
if (not ADOConnection1.Connected) then ADOConnection1.Connected:=True;
AdoTablePrograms.Active:=true;
ImportChannel;
ADOTablePrograms.Refresh;
CreateMediaList;
TabSheetProgram.Show;
end;
解决方案 »
- Delphi串口实时采集
- 请教﹕Delphi6写的组件为什么到Delphi2005上编译不过﹗
- 请问RichView部件在那个选项卡利?我怎么找不到啊??另外它的用法和RichEdit部件一样吗??
- 在Delphi中单步调试怎么不能在鼠标位置显示变量的结果呀!真怀恋VB的单步调试啊!
- 关于OpenPictureDialog控件的问题,请高手回答
- OpenDialog的小问题
- 在ppReport1中如何自动创建p_ppLabel
- 下载!!!!急!!!!!!!!!!
- 有钱大家一起挣,一起花!
- 什么函数可以删除字符串指针变量中的某个或某几个字符?delete()不行哦。。。
- 怎样实现象Office一样,刚打开程序显示一副图片,过几秒再进入程序主窗体?
- 关于Tadoquery的使用问题?
关于上面代码,你在用adquery前应该先将其close,然后再sql.clear....sql.execsql.
1. //删除原来的记录
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('delete files');////////////没有from吧
ADOQuery1.ExecSQL;
2.在所有SQL.Clear前,应该先Close