New to Delphi

Hi

I used to be a VB 6 Programmer and now I have started Delphi, few days ago.

I am looking for some way in Delphi, where we can select records in a RECORDSET and then that RECORDSET can be used to compare , displaying or decision making.

2- A method other than INSERT INTO for adding records to database,
like in VB we do ADD NEW and then specify individual records and their values.

so actually i want to translate following VB 6 code into Delphi by using ADO.

rs.open "Select * from table-1" ,cn,2,3

field1.text=rs![name]
field2.text=rs![age]

rs.close

or

rs.open "Select * from table-1" ,cn,2,3

rs.add
rs![name]=field1.text
rs![age]=field1.text
rs.update
rs.close



thanks
hellorazaAsked:
Who is Participating?
 
jimyXCommented:
About Delphi is full of samples and tips & Tricks. Also Torry.
0
 
jimyXCommented:
In Delphi the common ADO Components are ADOConnection, ADOTable and ADOQuery.

You use the ADOConnection to setup the connection to your database, by intializing the connection via the property "ConnectionString". Then use AdoQuery or AdoTable to connect to your table(s) in that DB, after adjusting the property "Connection".

The AdoQuery uses SQL to fetch data from the DB Table, AdoTable loads the entire Table when connected, so you better use AdoQuery.


To load data from your table:
  // AdoQuery
  AdoQuery1.Close;
  AdoQuery1.SQL.Text := 'Select * from YourTableName';
  AdoQuery1.Open;
  Edit1.Text := AdoQuery1.FieldByName('name').AsString;
  Edit2.Text := AdoQuery1.FieldByName('age').AsString;
  AdoQuery1.Close;

  // AdoTable
  // You must set the Table Name property to identify the intended Table
  AdoTable1.Open;
  Edit1.Text := AdoTable1.FieldByName('name').AsString;
  Edit2.Text := AdoTable1.FieldByName('age').AsString;
  AdoTable1.Close;


To insert data to your Table:
  // AdoQuery
  AdoQuery1.Close;
  AdoQuery1.SQL.Text := 'Insert into YourTableName (name, age) Values ('+QuotedStr(Edit1.Text)+', '+QuotedStr(Edit2.Text)+')';
  AdoQuery1.ExecSQL;

  // Or you can use Parameters
  AdoQuery1.Close;
  AdoQuery1.SQL.Text := 'Insert into YourTableName (name, age) Values (:ParaName, :ParaAge)';
  AdoQuery1.Parameters.ParamByName('ParaName').AsString := Edit1.Text;
  AdoQuery1.Parameters.ParamByName('ParaAge').AsString := Edit2.Text;
  AdoQuery1.ExecSQL;

  // AdoTable
  ADOTable1.Insert;
  ADOTable1.FieldByName('name').AsString := Edit1.Text;
  ADOTable1.FieldByName('age').AsString := Edit2.Text;
  ADOTable1.Post;

  // Or
  ADOTable1.InsertRecord(Edit1.Text, Edit2.Text);


You did the right thing by moving to Delphi.

PS: I just provided a quick info here, but you need to read a complete reference to learn more about how to use Delphi Database.
0
 
hellorazaAuthor Commented:

Thanks .

Can you please recommend me any website, where I can find some sample applications to get an idea about language basics and some tips and tricks.

regards.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
jimyXCommented:
There are many sites actually, but right now I have two in mind Torry's and About Delphi.

Also you can google for articles, free lessons or any particular issue you would like to learn about.

And of course EE will back you up if you needed support.
0
 
hellorazaAuthor Commented:
Thanks
0
 
jimyXCommented:
Here is a nice book "Mastering Delphi 7"
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.