数据库是access的mdb文件,里面有四个表,
一个Tadoconnection控件wz,连接用jet oledb 4.0,一个Tadoquery qrylian,
一个Tdatasource ds_lian 其dataset属性是qrylian,
界面中用了Tdbgrideh,当进行删除操作时,出错,部分源码如下:
procedure TfrmLiansz.BtnDeleteClick(Sender: TObject);
begin
if Application.MessageBox('您确认要删除此记录吗?',
PChar(application.title),mb_IconInformation+mb_YesNo)=idYes then
begin
ExecQuery(dm.qrylian,'delete from lian where id_lian='
+quotedstr(dm.qrylian.fieldbyname('id_lian').asstring));
RefreshQuery(dm.qrylian);
end;
end;
function ExecQuery(query:TADOQuery;SqlStr:string):boolean;
begin
query.close;
query.sql.clear;
query.sql.add(sqlstr);
try
query.ExecSQL;
except
ShowMessage('执行'+query.name+'出错,sql语句为:'+sqlstr);
result := false;
exit;
end;
result := true;
end;
function RefreshQuery(query:TADOQuery;SetFocus:boolean=false):boolean;
var place : TBookmark;
begin
result := true;
if not setfocus then
begin
query.filter := '';
query.filtered := false;
query.close;
try
query.open;
except
result := false;
end;
exit;
end;
place := nil;
try
if ((query.recordcount>1) and query.BookmarkValid(place)) then
place := query.GetBookmark;
query.close;
query.open;
if query.recordcount>1 then
begin
try
query.GotoBookmark(place);
finally
query.FreeBookmark(place);
end;
end;
except
result := false;
end;
end;
哪里有错?