简体   繁体   中英

Delete Multiselection rows of a dbgrid

Hello I need ur help for Deleting a number of rows in a dbgrid first my database is access and the error of deleting is "insufficient key conlumn information for updating or refreshin"

and adoquery related with dbgrid is:

SELECT tblMessages.*, tblMessages.Direction, tblContacts.Name FROM tblMessages LEFT JOIN tblContacts ON tblMessages.MobileNumber = tblContacts.MobileNum WHERE (((tblMessages.Direction)=1))

and method of delting is : adoquery1.delete;

This is not related to dbGrid, it is your dataset (adoQuery1) which does the action. dbGrid just visualizes your dataset records.

Make sure all your tables have primary key fields. I guess you should also include primary keys of both joined tables in the SELECT statement too.

There is a known bug in Microsoft ADO which I am not sure if it is fixed in the latest version or not; that is:

BUG: Problem Updating ADO Hierarchical Recordset When Join Tables Share Same Column Name

It says, if the primary key in one table has the same name as one of the fields in the other table, and the tables are joined together, then you may get that " Insufficient key column information for updating or refreshing. " error.

BTW, In your SELECT statement, you already have tblMessages.*, why are you including tblMessages.Directions too?

"insufficient key conlumn information for updating or refreshin" This error means that you are refreshing your DBGRID or dataquery after you deleted your record you can simply do this

 var
  sql_String;
begin
 sql_:'DELETE * FROM [yourTableName] WHERE [id] = '+DBGRID.Fields[0].AsInteger; // OR whichever Fielnumber that stores id (PrimaryKey) of the table
 AdoQuery1.Active:= False;
 AdoQuery1.SQL.Clear;
 AdoQuery1.SQL.Add(sql_);
 AdoQuery1.ExecSQL;
 // to refresh your data you have to deactive and active the data that is showing your data in the query
 MainData.Active:= False;
 MainData.Active:= True;
end;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM