insert data, help me.

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Goretz
Posts: 10
Joined: Mon 07 Aug 2006 10:26
Contact:

insert data, help me.

Post by Goretz » Mon 07 Aug 2006 10:32

hello I am new to Delphi. i want to insert new record to mysql database but don't know how. the connection using mysqlaccess is success but i don't know which components to use to insert data. i just want to insert several data and put it into a database, no need to display it meaning i don't want to use navigator or dbgrid. i just want to click on the enter button and the data will go straight to the database. can someone pls help me what components to use and where to put the statement?
Thanks :?:

Jackson
Posts: 512
Joined: Thu 26 Jan 2006 10:06

Post by Jackson » Tue 08 Aug 2006 11:59

You can use TMyCommand component to insert data using your statement.
For example:

Code: Select all

var
  MyCommand: TMyCommand;
...
  MyCommand.SQL.Text := 'insert into TableName(ID, c_int) values(10, 20)';
  MyCommand.Execute;
You can also use TMyQuery, and INSERT, UPDATE, DELETE and REFRESH statements will be generated automatically:

Code: Select all

var
  MyQuery: TMyQuery;
...
  MyQuery.SQL.Text := 'select * from TableName';
  MyQuery.Open;

  MyQuery.Insert;
  MyQuery.FieldByName('ID').AsInteger := 10;
  MyQuery.FieldByName('c_int').AsInteger := 20;
  MyQuery.Post;

Goretz
Posts: 10
Joined: Mon 07 Aug 2006 10:26
Contact:

Post by Goretz » Wed 09 Aug 2006 04:05

Thanks a bunch for the help! I have one more question. Can i use string grid to insert data? the string grid will not be displaying any data but only for inserting. Thanks

Jackson
Posts: 512
Joined: Thu 26 Jan 2006 10:06

Post by Jackson » Mon 14 Aug 2006 09:06

You can use TStringGrid but using TDBGrid is more simple.

Post Reply