Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 815975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:45:49+00:00 2026-05-15T01:45:49+00:00

I am a complete beginner here. Can someone please post some Delphi code to

  • 0

I am a complete beginner here. Can someone please post some Delphi code to

  • create a database
  • add a simple table
  • close the database

then, later

  • open a database
  • read each table
  • read each field of a given table
  • perform a simple search

Sorry to be so clueless. I did google, but didn’t find a useful tutorial …

In addition, it would be useful if the underlying database were MySql (5.1.36) (I don’t even know if that makes any difference)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T01:45:50+00:00Added an answer on May 15, 2026 at 1:45 am

    @mawg, i wrote an simple program for you to ilustrate how work with ADO and Delphi. this is an console application, but explains the basics.

    before you execute this code you must download and install the odbc connector from this location.

    You can improve and adapt this code to your requirements.

    program ProjectMysqlADO;
    
    {$APPTYPE CONSOLE}
    
    uses
      ActiveX,
      DB,
      ADODB,
      SysUtils;
    
    const
    //the connection string
    StrConnection='Driver={MySQL ODBC 3.51 Driver};Server=%s;Database=%s;User=%s; Password=%s;Option=3;';
    
    
    var
    AdoConnection : TADOConnection;
    
    procedure SetupConnection(DataBase:String);//Open a connection
    begin
      Writeln('Connecting to MySQL');
      AdoConnection:=TADOConnection.Create(nil);
      AdoConnection.LoginPrompt:=False;//dont ask for the login parameters
      AdoConnection.ConnectionString:=Format(StrConnection,['your_server',DataBase,'your_user','your_password']);
      AdoConnection.Connected:=True; //open the connection
      Writeln('Connected');
    end;
    
    procedure CloseConnection;//Close an open connection
    begin
      Writeln('Closing connection to MySQL');
      if AdoConnection.Connected then
      AdoConnection.Close;
      AdoConnection.Free;
      Writeln('Connection closed');
    end;
    
    procedure CreateDatabase(Database:string);
    begin
      Writeln('Creating Database '+database);
      AdoConnection.Execute('CREATE DATABASE IF NOT EXISTS '+Database,cmdText);
      Writeln('Database '+database+' created');
    end;
    
    procedure CreateTables;
    begin
      Writeln('Creating Tables');
      AdoConnection.Execute(
      'CREATE TABLE IF NOT EXISTS customers ('+
      'id      INT,'+
      'name    VARCHAR(100),'+
      'country VARCHAR(25) )',cmdText);
      Writeln('Tables Created');
    end;
    
    
    procedure DeleteData;
    begin
      Writeln('Deleting dummy data');
      AdoConnection.Execute('DELETE FROM customers');
      Writeln('Data deleted');
    end;
    
    procedure InsertData;
    
        Procedure InsertReg(id:integer;name,country:string);
        var
        ADOCommand : TADOCommand;
        begin
          ADOCommand:=TADOCommand.Create(nil);
          try
           ADOCommand.Connection:=AdoConnection;
           ADOCommand.Parameters.Clear;
           ADOCommand.CommandText:='INSERT INTO customers (id,name,country) VALUES (:id,:name,:country)';
           ADOCommand.ParamCheck:=False;
           ADOCommand.Parameters.ParamByName('id').Value      := id;
           ADOCommand.Parameters.ParamByName('name').Value    := name;
           ADOCommand.Parameters.ParamByName('country').Value := country;
           ADOCommand.Execute;
          finally
          ADOCommand.Free;
          end;
        end;
    
    begin
        Writeln('Inserting Data');
        InsertReg(1,'Lilian Kelly','UK');
        InsertReg(2,'John and Sons','USA');
        InsertReg(3,'William Suo','USA');
        InsertReg(4,'MARCOTEC','UK');
        Writeln('Data Inserted');
    end;
    
    procedure ReadData;
    var
      AdoQuery : TADOQuery;
    begin
       AdoQuery:=TADOQuery.Create(nil);
       try
        AdoQuery.Connection:=AdoConnection;
        AdoQuery.SQL.Add('SELECT * FROM customers');
        AdoQuery.Open;
        while not  AdoQuery.eof do
        begin
          Writeln(format('%s %s %s',[AdoQuery.FieldByname('id').AsString,AdoQuery.FieldByname('name').AsString,AdoQuery.FieldByname('country').AsString]));
          AdoQuery.Next;
        end;
       finally
       AdoQuery.Free;
       end;
    end;
    
    begin
      CoInitialize(nil); // call CoInitialize()
      try
           Writeln('Init');
           try
             SetupConnection('mysql'); //first will connect to the  mysql database , this database always exist
             CreateDatabase('Mydb'); //now we create the database
             CloseConnection; //close the original connection
             SetupConnection('Mydb'); //open the connection pointing to the Mydb database
             CreateTables; //create a sample table
             DeleteData; //Delete the dummy data before insert
             InsertData; //insert a dummy data
             ReadData; //read the inserted data
             CloseConnection; //close the connection
           except
             on E : Exception do
               Writeln(E.Classname, ': ', E.Message);
           end;
          Readln;
      finally
       CoUnInitialize; // free memory
      end;
    end.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 446k
  • Answers 446k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer are you using a javascript framework? If you use jQuery… May 15, 2026 at 7:07 pm
  • Editorial Team
    Editorial Team added an answer You can try this: http://www.somacon.com/p42.php Or even easier: http://www.inventec.ch/chdh/notes/14.htm For… May 15, 2026 at 7:07 pm
  • Editorial Team
    Editorial Team added an answer The border css property will increase all elements "outer" size,… May 15, 2026 at 7:07 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.