Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

writing to a db in delphi

Status
Not open for further replies.

helloise

Programmer
Oct 12, 2009
8
0
0
ZA
i have a DBEditfor the staff name and a button on my form. i type something in the "textbox" and when i click on the button i want to do the following:

1. create the next available ID in the staff table
2. write the ID and the value of the textbox(staff name) to the staff table

we use firebird database and the interbase controls from the IDE delphi 2010

how do i do this pls?
i need a step by step pls...
thanks
 
i've done all of that.... i just want to know the code for writing to the db...

i found this but my controls dont have these properties...i am using the 2010 ide
Displaying and editing fields with TDBEdit
TDBEdit is a data-aware version of the TEdit component. TDBEdit displays the current
value of a data field to which it is linked. You can also modify values in this component.
For example, suppose DataSource1 is a TDataSource component that is active and linked
to an open TTable called Customer. You can then create a TDBEdit component
(DBEdit1), and set its properties as follows:
• DataSource: DataSource1
• DataField: CUSTNO
The DBEdit1 component immediately displays the value of the current row in the
CUSTNO column of the CUSTOMER table, both at design time and at run time.
Figure 4.3 TDBEdit component at design time
Editing a field
A user can modify a database field in a TDBEdit component if:
1 The Dataset is in Edit state.
2 The Can Modify property of the Dataset is True.
3 The ReadOnly property of TDBEdit is False.
Note Edits made to a field must be posted to the database by using a navigation or Post button
on a TDBNavigator component.

i dont have the properties mentioned in 1 and 2?????????
i run my app and i cannot endit the DBEdit!!!!!!!!!
 
You have to put the dataset into edit mode. That can happen automatically if your db-aware controls are allowed to do that. And then you have to post the changes - one way is by using the dbNavigator component you mentioned. Or by calling dataset.post.

The two properties you mentioned above aren't published so you don't see them in the IDE. You check/set those at runtime. Can Modify is used to tell you whether the result set that have can can be edited - you can't change that. That's data that the database engine passed along. Each database will have it's own oddities/advantages which you just have to sort out.

This would be a good place to get you started with DB programming with Delphi.
 
thank you..will have a look at it...i am new to delphi and dont know all theses things...C# muuuuch better! :)
 
i have a IBtable and IBQuery...which one would be the datatset?? i try and set those properties dinamically but get errors:

DBEdit1.ReadOnly := False;
DBGrid1.ReadOnly := False;

IBQuery1.CanModify := True; //here
IBTable1.CanModify := True; // and here

errors sais: cannot assign read-only property????
 
IBQuery is a descendant of TDataSet. So is your IBTable.

.CanModify is not a property that you are allowed to change. When you query the database and get the result set the database will let you know if you can update the database by changing records within the result set. I don't know the logic behind why a result set would be editable but one condition might be that your result set must contain all of the primary key fields.

From the IBPhoenix website:
IBQuery returns a read only result set from a SQL SELECT statement assigned to its SQL property and executed by calling its Open method.

More links courtesy of Google:

 
thanks..my query just selects the whole staff table
i also dont have the query.open statement...
 
Does your project require you to work with Interbase/Firebird or are you using that database to learn with?
 
i MUST use firebird/interbase...our software was written using that..

i added the query.open statement but nothing still...cant edit the dbedit....
 
Are you reading what I'm posting? You CANNOT edit the result set of your IBQuery. You can't. Stop trying.

Use the links I posted you to learn how to achieve what you want to do.
 
what link would that be?? the delphi.about.com i went through already...a few times...

the felix one is broken..any other site/s where i can actually follow tutorials on this pls?

i am doing something wrong obviously but know to little to figure it out... i unfortunately dont have time to read through masses of websites...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top