0

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;

2 Answers 2

1

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?

Sign up to request clarification or add additional context in comments.

2 Comments

dear , this error didnot occure in joining thats apear in deleting by method adoqurey1.delete;
I know it occurs while deleting a record. When you delete a record, DELETE statement has to find the record in the recordset. Obviously it does not have enough info about the record which is supposed to be deleted. I told you that ADO has a bug which causes this, and that error occurs while deleting a record. So you should check what I mentioned in my answer.
0

"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;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.