procedure TForm1.Button1Click(Sender: TObject);
begin
with TStringList.Create do try
DBGlist.DataSource.DataSet.First;
while not DBGlist.DataSource.DataSet.Eof do begin
if DBGlist.SelectedRows.CurrentRowSelected then
Add(IntToStr(DBGlist.DataSource.DataSet.RecNo));
DBGlist.DataSource.DataSet.Next;
end;
while not DBGlist.DataSource.DataSet.Bof do begin
if IndexOf(IntToStr(DBGlist.DataSource.DataSet.RecNo)) >= 0 then
DBGlist.DataSource.DataSet.Delete;
DBGlist.DataSource.DataSet.Prior;
end;
finally
Free;
end;
end;
begin
with TStringList.Create do try
DBGlist.DataSource.DataSet.First;
while not DBGlist.DataSource.DataSet.Eof do begin
if DBGlist.SelectedRows.CurrentRowSelected then
Add(IntToStr(DBGlist.DataSource.DataSet.RecNo));
DBGlist.DataSource.DataSet.Next;
end;
while not DBGlist.DataSource.DataSet.Bof do begin
if IndexOf(IntToStr(DBGlist.DataSource.DataSet.RecNo)) >= 0 then
DBGlist.DataSource.DataSet.Delete;
DBGlist.DataSource.DataSet.Prior;
end;
finally
Free;
end;
end;
谢谢:)
var i:integer;
booklist:Tbooklist;
book:TbookStr;
begin
book:=DataModule1.adotable1.Book;
booklist:=DBGrid1.SelectedRows;
if booklist.Count>0 then
begin
if MessageDlg('是否要删除这些部门。',mtConfirmation,[mbyes,mbno],0)=mryes then
begin
for i:=0 to booklist.Count-1 do
begin
DataModule1.adotable1.Book:=booklist[i];
DataModule1.adotable1.Delete;
end;
BookMarkList.Clear;
end;
end;
end;
不关用上面那种方法,
最后还是提示这个错误,
是不是有什么控件属性设的不对啊
我用:
adoconn->adoquery->datasource->dbgrid
对了,我的数据是从两张表里取出的,
不知是不是跟这有关。
我的数据是从两个表中取出的,
是不是跟这个有关???
你说的第三点怎么解决啊?
procedure TForm1.Button1Click(Sender: TObject);
begin
with TStringList.Create do try
DBGlist.DataSource.DataSet.First;
while not DBGlist.DataSource.DataSet.Eof do begin
if DBGlist.SelectedRows.CurrentRowSelected then
Add(IntToStr(DBGlist.DataSource.DataSet.RecNo));
DBGlist.DataSource.DataSet.Next;
end;
while not DBGlist.DataSource.DataSet.Bof do begin
if IndexOf(IntToStr(DBGlist.DataSource.DataSet.RecNo)) >= 0 then
DBGlist.DataSource.DataSet.Delete;
DBGlist.DataSource.DataSet.Prior;
end;
finally
Free;
end;
end;
你的方法试了,到这句话
TViewForm1.DBGlist.DataSource.DataSet.Prior;
就提示:
---------------------------
Debugger Exception Notification
---------------------------
Project Project2.exe raised exception class EOleException with message '缺少更新或刷新的键列信息。'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------
我的数据是从两张表里取出的,应该是这个问题吧。不知道怎么解决?
是这句话:
DBGlist.DataSource.DataSet.Delete;
//删除选中的记录
var
strSql:string;
begin
with TStringList.Create do try
TViewForm1.DBGlist.DataSource.DataSet.First;
while not TViewForm1.DBGlist.DataSource.DataSet.Eof do begin
if TViewForm1.DBGlist.SelectedRows.CurrentRowSelected then
Add(IntToStr(TViewForm1.DBGlist.DataSource.DataSet.RecNo));
TViewForm1.DBGlist.DataSource.DataSet.Next;
end;
strSql := 'delete * from article where articleID =:id';
while not TViewForm1.DBGlist.DataSource.DataSet.Bof do begin
if IndexOf(IntToStr(TViewForm1.DBGlist.DataSource.DataSet.RecNo)) >= 0 then
// TViewForm1.DBGlist.DataSource.DataSet.Delete;
//获得被删除记录的ID(atricleID),并将它删除
begin
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add(strSql);
adoquery1.Parameters[0].Value := TViewForm1.DBGlist.DataSource.DataSet.Fields[0].Value;
//adoquery1.Parameters[0].Value := 20;
adoquery1.ExecSQL;
end;
TViewForm1.DBGlist.DataSource.DataSet.Prior;
end;
//adoqtv.Refresh;
//TViewForm1.DBGlist.Refresh;
//TViewForm1.DBGlist.DataSource.DataSet.FindFirst;
finally
Free;
end;
end;
这是我的改进,现在可以删除记录了,但是再刷新DBGRID时
还是有同样的错误。