Page 1 of 1

insert data, help me.

Posted: Mon 07 Aug 2006 10:32
by Goretz
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 :?:

Posted: Tue 08 Aug 2006 11:59
by Jackson
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;

Posted: Wed 09 Aug 2006 04:05
by Goretz
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

Posted: Mon 14 Aug 2006 09:06
by Jackson
You can use TStringGrid but using TDBGrid is more simple.