Add,update and delete by dbgrid lazarus / 16-Databases ---------------------------------------------------------------------- Gebo · 2025-03-14 19:24 please guys,I want any tutorials that explain how to add new record or edit through dbgrid ---------------------------------------------------------------------- 1HuntnMan · 2025-03-14 20:42 Probably need more information. What database are you using. Easy way is on your form put a panel at the top and then put a DBNavigator on the panel. Then below the panel put your DBGrid. Connect the Navigator and the Grid to a Dataset. The Dataset is pointing to your Database but all this depends on whether your Database is SQL or SQLite3. Or could be TDbf. Start reading online a good start for SQLite is https://www.tweaking4all.com/software-development/lazarus- development/lazarus-pascal-getting-started-with-sqlite/ or this one for SQL:  https://wiki.freepascal.org/SQLdb_Tutorial1 ---------------------------------------------------------------------- Gebo · 2025-03-15 07:47 I use mariadb through odbc connection . I want to create buttons myself ,I don't want to use dbnavigator. ---------------------------------------------------------------------- paweld · 2025-03-15 08:29 to add a new recordCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i DBGrid1.DataSource.DataSet.Insert;to edit recordCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i DBGrid1.DataSource.DataSet.Edit;to delete a recordCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i DBGrid1.DataSource.DataSet.Delete; to confirm the add/editCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i DBGrid1.DataSource.DataSet.Post; to cancel the add/editCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i DBGrid1.DataSource.DataSet.Cancel; When approving and canceling changes, it's a good idea to make sure the dataset is in add/edit mode - the State property is used for this, e.g. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i if not (DBGrid1.DataSource.DataSet.State in [dsInsert, dsEdit]) then  begin  ShowMessage('Dataset is not in insert/edit mode');    exit;  end; ---------------------------------------------------------------------- wcage03 · 2025-03-18 18:42 For simple database scenarios, the DBGrid can pretty much handle the inserts and updates automatically. If you have the property AutoEdit turned on, then you can double click on a cell to start the editor, make your changes, move to another row and the changes will be saved. If you continue past the last row displayed, a row insert will occur allowing you to enter in the values needed. Again, moving to another row will automatically save your changes. If the data table is more complex, you will need to add SQL to the InserSQL, UpdateSQL, and/or DeleteSQL properties. For example, if you are displaying data from a view in the grid, but you want. updates to be performed on the underlying tables, you can create your SQL so that is accommodated. Other things like auto incrementing values can be tricky and the requirements vary by the database. You will also need to make sure that you have logic to ensure that any open transactions are recognized and saved if the form is exited and also decide how you want to handle transactions and commits. Since you are asking this question you are, I would recommend going the approach of automatically committing transactions. Remember to select the option to keep the dataset open after a commit also. Good luck!