I need a way of adding data to a database using my delphi form i can handle the sql to add data to a database on ms access but i just do not know how to do it through a delphi form.

In other word i just need to know where i can put in a procedure that will allow the addition of data to a database using sql commands.

It is not a server, i just want to be able to add it to a drive on a local drive
thanks

Dani AI

Generated

Practical, copy‑ready patterns for saving a record from a Delphi form to a local Access file, plus the most common causes of connection failures seen in this thread (building on 's direction and the connection problem reported by ). The examples use parameterized SQL (safer and simpler than string concatenation) and show both dbGo/ADO (older Delphi) and FireDAC (newer Delphi).

For dbGo (TADOConnection / TADOQuery) — put this in a button OnClick. It ensures the connection is open, uses parameters and catches exceptions:

procedure TForm1.btnSaveClick(Sender: TObject);
begin
  if not ADOConnection1.Connected then
    ADOConnection1.Connected := True;
  ADOQuery1.Close;
  ADOQuery1.SQL.Text := 'INSERT INTO People ([FullName],[Age]) VALUES (:FullName,:Age)';
  ADOQuery1.Parameters.ParamByName('FullName').Value := Trim(EditName.Text);
  ADOQuery1.Parameters.ParamByName('Age').Value := StrToIntDef(EditAge.Text, 0);
  try
    ADOQuery1.ExecSQL;
  except
    on E: Exception do
      ShowMessage('Database error: ' + E.Message);
  end;
end;

For FireDAC (TFDConnection / TFDQuery) — same pattern, slightly different component/API:

procedure TForm1.btnSaveClick(Sender: TObject);
begin
  FDConnection1.Connected := True;
  FDQuery1.Close;
  FDQuery1.SQL.Text := 'INSERT INTO People (FullName, Age) VALUES (:FullName, :Age)';
  FDQuery1.Params.ParamByName('FullName').AsString := Trim(EditName.Text);
  FDQuery1.Params.ParamByName('Age').AsInteger := StrToIntDef(EditAge.Text, 0);
  try
    FDQuery1.ExecSQL;
  except
    on E: Exception do
      ShowMessage('Database error: ' + E.Message);
  end;
end;

Quick troubleshooting notes (most frequent causes): ensure the connection string uses the correct provider for the Access file type (Jet for .mdb, ACE for .accdb); avoid accidentally supplying a long/incorrect DSN string to the wrong driver; check 32‑bit vs 64‑bit driver mismatch on modern Windows (Access drivers are commonly 32‑bit); bracket reserved names (e.g., [Name]); use transactions for bulk inserts (BeginTrans / CommitTrans) and always use parameters to avoid quoting and injection problems.

Recommended Answers

All 3 Replies

I need a way of adding data to a database using my delphi form i can handle the sql to add data to a database on ms access but i just do not know how to do it through a delphi form.

In other word i just need to know where i can put in a procedure that will allow the addition of data to a database using sql commands.

It is not a server, i just want to be able to add it to a drive on a local drive
thanks

Hello My Frind
you can use ADOConnection for Connecting to Access Database and also use ADOQuery And ADOCommand for Writing and Executing SQL Statements.

After connecting the ADOcommand and trying to enter command text it tells me

[microsoft][OBDC driver manager] data source name too long

Dear Frind
Here is an example project with simple database
I trye to use tow method for inserting data into database
I hope that it is useful for you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.