INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Help to create buttons - beginner

Help to create buttons - beginner

(OP)
Hello, Im a beginner and i need help with my problem.
How to create insert/save/update/delete and clear Fields(DBEdit) buttons for mysql database using delphi.

This is my example.

First I create mysql database:
create database Contacts;

create table coktacts(
id int auto_increment primary key not null,
First_name varchar(25) not null,
Last_name varchar(25) not null,
Address varchar(50) not null,
Country varchar(25) not null,
Phone varchar(13));


Then I create application in delphi.

File -> New -> VLC Forms Application

In Forms I Use:

DBGrid
5 buttons (insert/save/Update/delete/clear)
AdoConnection
AdoDataset
Data Source

then set my AdoConnection:
- ConnectionString: Find my source to connection ...
- LoginPrompt: false
- Connected: True
- Name: AdoConnection1

Then set AdoDataSet:
Connection: AdoConnection1
Name: AdoDataSet1
CommandType: cmdTable
CommandText: Contacts
for dataset I use Field Editor-add fields-Drag and Drop to Form.

Then set DAtaSource:
DataSet: AdoDataSet1
Name: DataSource1

Then set DBGrid:
DataSource: DataSource1
Columns:(TDBGridColumns): id, First Name, Last Name, Address, Country, Phone.

For Show my database into DBgrid I use Code:
for procedure TForm3.FormCreate(Sender: TObject);
begin
ADODataSet1.Active := true;
end;

Question 1: how to create insert/save/update/delete/clear buttons?
I dont want to use DBnavigator.

When I click INSERT button I want to clear DBEdits fiels(Firstname,lastname,address ...) input new contact info and SAVE to my database.

RE: Help to create buttons - beginner

I don't have Delphi open so this might not be exactly perfect:

If you drop a TActions item on to your form and then double-click on it you can then right-click in the actions editor and automatically insert a bunch of database related actions. Connect the newly created actions to your datasource and then link your buttons to the actions and Delphi will take care of the rest.

RE: Help to create buttons - beginner

- For example your table has foloowing fields (Tabel name is Music) :
Title_OF_CD , Artist , Genre & Price

For your 'Insert Button'
you want to insert a new record
you would do the following :

Insert Into Music 'Believe','Justin Bieber','Pop','$10';

it follows this principle
- Insert Into <Table> <Field1(Titel_OF_CD)>,
<Field2(Artists)>,<Field3(Genre)>,<Field4(Price)>;
your data should be inserted according to your fields, so whatever field is first's data should be specified first.

For your 'Update Button'
you want to change the artist name of a certain CD
you would do the following :

Update Music Set Artist = 'Justin Bieber' Where Title_OF_CD = 'Believe';

it follows this principle
-Updat <Table> Set <Field> = <Value> Where <Criteria>
If you want to update more than one field
-Updat <Table> Set <Field> = <Value>, <Field> = <Value>
Where <Criteria>

For you 'Delete Button'
You want to delete all records where the Atrist is Eminem
you would do the following :

Delete From Music Where Artist = 'Eminem';

it would follow this principle
- Delete From <Table> Where <Field> = <Criteris>;
If you want to be more precise
- Delete From <Table> Where <Field> = <Criteria> and <Field> = <Criteria> and...

As for your Save and clear I'm not sure myself as far as I know what ever you insert or delete is automaticly saved, and clear to me is same as delete.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close