Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

[HELP!!] ADO Query Error With Delphi

I want to query some data from access database. I am using TADOQuery to do ti but I found this statement isn't give me some resultset can anyone help me ???

here is my sourcecode

with HRTransDataModule.T_DeptQ do
begin
Active := false;
SQL.Clear;
SQL.Add('SELECT Tanggal, NamaDep, Keterangan');
SQL.Add('FROM T_Dept');
SQL.Add('WHERE KdKar="'+DBText1.Caption+'"');
SQL.Add('AND Tanggal BETWEEN '+FormatDateTime('dd/mm/yyyy', DateTimePicker3.Date)+'AND '+FormatDateTime('dd/mm/yyyy', DateTimePicker4.Date));
Active := true;
end;

nb : sorry for my bad english

Comments

  • MasterijnMasterijn Posts: 188Member
    : I want to query some data from access database. I am using TADOQuery to do ti but I found this statement isn't give me some resultset can anyone help me ???
    :
    : here is my sourcecode
    :
    : with HRTransDataModule.T_DeptQ do
    : begin
    : Active := false;
    : SQL.Clear;
    : SQL.Add('SELECT Tanggal, NamaDep, Keterangan');
    : SQL.Add('FROM T_Dept');
    : SQL.Add('WHERE KdKar="'+DBText1.Caption+'"');
    : SQL.Add('AND Tanggal BETWEEN '+FormatDateTime('dd/mm/yyyy', DateTimePicker3.Date)+'AND '+FormatDateTime('dd/mm/yyyy', DateTimePicker4.Date));
    : Active := true;
    : end;
    :
    : nb : sorry for my bad english
    Hello Gonjuzx,
    The problem is that you didn't quote the datetimes.
    By the way it's more easy (and safer!) to use static sql with parameters like:
    [code]
    SELECT Tanggal
    , NamaDep
    , Keterangan
    FROM T_Dept
    WHERE KdKar=:KdKar
    AND Tanggal BETWEEN :StartDate AND :EndDate
    [/code]
    then the code will be like
    [code]
    with HRTransDataModule.T_DeptQ, Parameters do
    begin
    Active := false;
    ParamByName('KdKar').Value := DBText1.Caption;
    ParamByName('StartDate').Value := Trunc(DateTimePicker3.Date); // Trunc is date-part only discards the time-part
    ParamByName('EndDate').Value := Trunc(DateTimePicker4.Date);
    Active := true;
    end;
    [/code]

  • gonjuzxgonjuzx Posts: 2Member
    but i want to ask more about parameters.
    can parameters detect the datatype from the input ???
    and what the meaning of direction ???

    thanks.
  • MasterijnMasterijn Posts: 188Member
    : but i want to ask more about parameters.
    : can parameters detect the datatype from the input ???
    Sometimes this is the case, but you can always set the correct datatype yourself (Sometimes it's a good idea to set an example value as well).
    : and what the meaning of direction ???
    Standard query parameters are in-parameters, this means they supply a value. Out-parameters can be used to retrieve a value. Mostly by stored procedures.



Sign In or Register to comment.