How to insert a row (not record) into TDBGrid [SOLVED] lazarus / 16-Databases ---------------------------------------------------------------------- PaulW · 2011-05-22 23:49 I have a TDBGrid that I populate with the results of a query.  If the query returns no records, I want to populate the TDBGrid with one row.  I've tried to use    MyGrid.InsertRecord([1,'two','three']);      or    MyGrid_DataSource.DataSet.InsertRecord([1,'two','three']); Both result in an error: Cannot update a complex query with more than one table    Should I somehow unbound the grid from it's datasource?  If so, then could I just use MyGrid.InsertRecord()? ---------------------------------------------------------------------- exdatis · 2011-05-23 05:15 Use UpdateQuery with query(update object = update_query) ---------------------------------------------------------------------- PaulW · 2011-05-23 21:56 Thanks.  I'll look into your suggestion. ---------------------------------------------------------------------- 99Percent · 2011-05-24 05:12 use TBufDataSet or TMemDataSet and then switch the datasource to it before inserting a record. You will need to define the fields to be the same. ---------------------------------------------------------------------- JD · 2011-05-24 10:38 Quote from: PaulW on May 23, 2011, 01:49:52 amI have a TDBGrid that I populate with the results of a query.  If the query returns no records, I want to populate the TDBGrid with one row.  I've tried to use    MyGrid.InsertRecord([1,'two','three']);      or    MyGrid_DataSource.DataSet.InsertRecord([1,'two','three']); Both result in an error: Cannot update a complex query with more than one table    Should I somehow unbound the grid from it's datasource?  If so, then could I just use MyGrid.InsertRecord()?    I once had this problem because I had a form with several TEdit fields and a TDBGrid which was supposed to be updated from a query on 4 different tables. The TEdit fields & the TDBGrid had the same datasource. I kept getting the error "cannot update a complex query with more than one table" everytime I tried to update the TDBGrid. I solved the problem by creating a new datasource & a new query unique to the TDBGrid. That may work for you. If it dosen't, post a sample of your code so we can better understand the problem. ---------------------------------------------------------------------- PaulW · 2011-05-25 20:08 Thanks for the suggestions.  I'll dig into them and see how it goes.  For now, I solved my problem by using an alternative query: If the first query returns a record, I fetch the fields for the grid from a table using the second query and a where clause based on the values from the first query.  If the first query returns no records, I fetch the fields for the grid from the table using a modified second query that I force to get the fields I want by hard-coding the where clause.  Certainly not a very elegant approach, but i works.  I'll do some more experimentation using the suggestions provided.  I'll mark this issue "solved".