Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert data into database [Delphi]

I'm trying using a TAdoTable component,

  • On form Create I call .Append() and in a button i call .Post()

but it loads the entire table! I don't need it to load anything, just need to insert a row into this table.

I was wondering if there is "good way" of inserting data into database with Ado, i already tried using the a "manual" approach with TAdoCommand but it doesn't seems right to me

  • I generate the INSERT query using Format() and all string fields are escaped with QuotedStr()

Thanks in advance!

Arthur.

like image 814
arthurprs Avatar asked Feb 26 '10 20:02

arthurprs


2 Answers

You can use a TADODataset (or TADOQuery).

The way I do it sometimes is with by setting the CommandText to return 0 records from the table, i.e. SELECT TOP 0 * FROM [table], then use .Append and .Post

But personally, I prefer writing the SQL, such as with a TADOCommand

like image 103
jasonpenny Avatar answered Nov 14 '22 16:11

jasonpenny


Use the TADOQuery object if you don't need to display the table's data.

Basically:

  • Use TADOQuery.SQL.Text to set the SQL command
  • Use TADOQuery.ExecSQL method to fire the SQL command
like image 6
AlexV Avatar answered Nov 14 '22 16:11

AlexV