select dbedit text depening on edit text

I have linked dbedit to a datasource and a field.
How can I have dbedit showing text from the database depending on edit text?
In the database I have
field1   field2      
(field1 has same text as edit)
(field2 is linked to dbedit)
So after my table opens if edit text = field1.text then dbedit.text = field2
However I do not want to replace edit with dbedit
Who is Participating?
Eddie ShipmanConnect With a Mentor All-around developerCommented:
Can you show an example, I still don't understand why you need TEdit's
Are you saying that you have a table defined something like this:

Field1  - contains the values from the TEdits
Field2 - contains the percentages, will be the TDBEdits

You can't have a separate DBEdit for each of those values without
having 10 datasets. the dataset will point to ONE ROW in your table
and the DBEdit's will point to the Field2 in THAT ROW.

You can select all the percentages from the table into a dataset and
then loop through and populate TEdits like this:
  while not Table1.EOF do
    if Table1.FieldByName('Field1').AsString = Edit1.Text then
      Edit11.Text := Table1.FieldByName('Field1').AsString;
    if Table2.FieldByName('Field1').AsString = Edit2.Text then
      Edit12.Text := Table1.FieldByName('Field1').AsString;
    if Table3.FieldByName('Field1').AsString = Edit3.Text then
      Edit13.Text := Table1.FieldByName('Field1').AsString;
    if Table4.FieldByName('Field1').AsString = Edit4.Text then
      Edit14.Text := Table1.FieldByName('Field1').AsString;
    if Table5.FieldByName('Field1').AsString = Edit5.Text then
      Edit15.Text := Table1.FieldByName('Field1').AsString;
    if Table6.FieldByName('Field1').AsString = Edit6.Text then
      Edit16.Text := Table1.FieldByName('Field1').AsString;
    if Table7.FieldByName('Field1').AsString = Edit7.Text then
      Edit17.Text := Table1.FieldByName('Field1').AsString;
    if Table8.FieldByName('Field1').AsString = Edit8.Text then
      Edit18.Text := Table1.FieldByName('Field1').AsString;
    if Table9.FieldByName('Field1').AsString = Edit9.Text then
      Edit19.Text := Table1.FieldByName('Field1').AsString;
    if Table10.FieldByName('Field1').AsString = Edit10.Text then
      Edit20.Text := Table1.FieldByName('Field1').AsString;

In the code above, you have a Table that points to your dataset containing the data.
Then you have 10 TEdits that contain your selections, and 10 TEdits that contain your
Eddie ShipmanAll-around developerCommented:
reformat your query to something like this:

Query1.SQL.Text := 'SELECT FIELD2 FROM TABLE WHERE FIELD1 = ' + QuotedStr(Edit1.Text);
VrtnarAuthor Commented:
But how do I display FIELD2 in my dbedit ??
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Eddie ShipmanAll-around developerCommented:
set the dbEdit's datafield to field2.
VrtnarAuthor Commented:
and if i have a couple of dbedits to change that way,what would be rigt?
Eddie ShipmanAll-around developerCommented:
You set the DataField property tothe field in the dataset that you want to show in the DBEdit.
VrtnarAuthor Commented:
edits are not the same...
Eddie ShipmanAll-around developerCommented:
I don't understand what you mean or what you want to do, here.
VrtnarAuthor Commented:
I have 10 edits that contain various text.
I have a table that contains the same texts from each edit and a percentage value for each entry.
Easy way would be to use dbedits to represent the table but instead i must use plain edit.
So next to edits I placed dbeditst to get the percentage.
So how can I filter them according to edittext

Forced accept.

EE Admin
All Courses

From novice to tech pro — start learning today.