Retrieving data from access db with ado components

Hey there guys,
I'm new with ADO componenets and i've a maybe-silly question.
How can i retrieve a field value from a access database?
[code]
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('select address from pay where id=665');
ADOQuery1.Open;
ADOQuery1.ExecSql;
[/code]
The target record is now loaded in ADOQuery1, but what's the way to retrieve address field value?
i think i should use parameters, but i don't know anything about them.
Thanks, in advance ;)

Comments

  • : Hey there guys,
    : I'm new with ADO componenets and i've a maybe-silly question.
    : How can i retrieve a field value from a access database?
    : [code]
    : ADOQuery1.SQL.Clear;
    : ADOQuery1.SQL.Add('select address from pay where id=665');
    : ADOQuery1.Open;
    : ADOQuery1.ExecSql;
    : [/code]
    : The target record is now loaded in ADOQuery1, but what's the way to retrieve address field value?
    : i think i should use parameters, but i don't know anything about them.
    : Thanks, in advance ;)
    :
    If you have the query component as the source for a TDBEdit, then the value should appear in the edit automatically.
  • Exactly...
    but i need this value to pass to another module as a parameter.
    Assume that table has the fields below:
    [italic]ID,Name,ImageAddress[/italic]

    The code below will load the target record to ADOQuery1 and for example a TDBEdit component can be loaded by its ImageAddress field value.
    But i can't access its value by DBEdit1.Text(for example),there's no Text property.
    [code]
    ADOQuery1.SQL.Clear;
    ADOQuery1.SQL.Add('select address from pay where id=665');
    ADOQuery1.Open;
    ADOQuery1.ExecSql;
    [/code]

    i wanna pass the value to another module:
    [code]
    LaunchImage(ImageAddress.Value!!);
    [/code]


    Thanks for your reply, i'm waiting;
  • [b][red]This message was edited by zibadian at 2006-7-29 22:18:29[/red][/b][hr]
    : Exactly...
    : but i need this value to pass to another module as a parameter.
    : Assume that table has the fields below:
    : [italic]ID,Name,ImageAddress[/italic]
    :
    : The code below will load the target record to ADOQuery1 and for example a TDBEdit component can be loaded by its ImageAddress field value.
    : But i can't access its value by DBEdit1.Text(for example),there's no Text property.
    : [code]
    : ADOQuery1.SQL.Clear;
    : ADOQuery1.SQL.Add('select address from pay where id=665');
    : ADOQuery1.Open;
    : ADOQuery1.ExecSql;
    : [/code]
    :
    : i wanna pass the value to another module:
    : [code]
    : LaunchImage(ImageAddress.Value!!);
    : [/code]
    :
    :
    : Thanks for your reply, i'm waiting;
    :
    There are two public properties which you can use for this: TDBEdit.Field and TDBEdit.Text (not published so not visible in Object Inspector).
    You can also use the TDataSet.Fields property or the TDataSet.FieldByName() method, if you don't want to pass the value through a visible component.
    In your example code this can easily be done:
    [code]
    LaunchImage(DBEdit1.Text);
    [/code]
    or this:
    [code]
    LaunchImage(ADOQuery1.FieldByName['image'].AsString);
    [/code]
  • : There are two public properties which you can use for this: TDBEdit.Field and TDBEdit.Text (not published so not visible in Object Inspector).
    : You can also use the TDataSet.Fields property or the TDataSet.FieldByName() method, if you don't want to pass the value through a visible component.
    : In your example code this can easily be done:
    : [code]
    : LaunchImage(DBEdit1.Text);
    : [/code]
    : or this:
    : [code]
    : LaunchImage(ADOQuery1.FieldByName['image'].AsString);
    : [/code]
    :

    You're great man, thank you so much.
    and i'm beholden :)
  • : Hey there guys,
    : I'm new with ADO componenets and i've a maybe-silly question.
    : How can i retrieve a field value from a access database?
    : [code]
    : ADOQuery1.SQL.Clear;
    : ADOQuery1.SQL.Add('select address from pay where id=665');
    : ADOQuery1.Open;
    : ADOQuery1.ExecSql;
    : [/code]
    : The target record is now loaded in ADOQuery1, but what's the way to retrieve address field value?
    : i think i should use parameters, but i don't know anything about them.
    : Thanks, in advance ;)
    :
    Example:
    [code]
    Edit1.Text := ADOQuery1.FieldByName('TheField').AsValue ;
    [/code]
    Use the appropriate Value where possible. Ie. If the data is a string, use .AsString.

    Tip:
    [code]
    ADOQuery1.SQL.Clear;
    ADOQuery1.SQL.Add('select address from pay where id=665');
    ADOQuery1.Open;
    ADOQuery1.ExecSql;
    [/code]

    As you are RETRIEVING data, you only need the Open command.
    Only use the ExecSql command if you are making a CHANGE to the table. Ie if you are using UPDATE, INSERT commands etc. The ExecSQL executes an action and here you're only wanting to retrieve data so you only need Open.

    Hope this helps.

    ----------
    Jonny

  • Thank you Jonny ;)
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories