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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why this query is empty? It have

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
Why this query is empty?
It have a record in datatabase that fill the requirements!

Code:

query1.close;
query1.sql.clear;
query1.sql.add('select * from sellers where seller=:param1;');
query1.Prepare;
query1.Params[0].asstring:='001';
query1.open;
 
Is the parameter a string? Looks like an integer to me, perhaps you should try using:
query1.params[0].asInteger := 001;

Hope this helps
::)
 
No. It's a string.
I don't know what's wrong...

To test it I make a little program:

I put a datasource component;
Dataset: Query1

I put a bde database component.
I change the properties:
Alias name: datasellers
Database Name: databasesellers
Params: I insert the necessary parameters.
LoginPrompt: False

I put a bde query component:
I change the properties:
Database Name: databasesellers

I put a button
and a DBGRID
I change the properties:
DataSource: Datasource1


The code:

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, DBGrids, DB, DBTables;

type
TForm1 = class(TForm)
DataSource1: TDataSource;
Query1: TQuery;
Database1: TDatabase;
DBGrid1: TDBGrid;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
database1.Connected:=true;
query1.close;
query1.sql.clear;
query1.sql.Add ('select * from artigos where codartigo=:param1;');
query1.Prepare;
query1.Params[0].Value:='001';
query1.open;

end;

end.


 
Try
query1.ParamByName('Param1').asstring := '001'
instead.

It depends on the database but some databases use the parameters for login info as well so params[0] might not be the one you think it is.

Good luck!
TealWren
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top