[Lazarus] SQLQuery1: Field not Found: "enquiryreferencenumber"

Joost van der Sluis joost at cnoc.nl
Wed May 28 10:46:52 CEST 2008


Op woensdag 28-05-2008 om 06:02 uur [tijdzone +0200], schreef Dave
Coventry:
> Hi.
> 
> Following Damien's instructions I have DROPped my original table and
> created a new one in it's place:
> 
> CREATE table registration (
> fname char(50),
> sname char(50),
> enquiryreferencenumber INT4 PRIMARY KEY DEFAULT nextval('reg_seq'))
> WITHOUT OIDS;
> 
> I have run my INSERT Query under PQConnection1 using the following arguments:
> 
>       sqlq:='INSERT INTO registration (fname,sname) ';
>       sqlq:=sqlq+'VALUES
> ('''+FName.Text+''','''+SName.Text+''')RETURNING
> enquiryreferencenumber;';
>       PQConnection1.Connected:=True;
>       PQConnection1.ExecuteDirect('Begin Work;');
>       PQConnection1.ExecuteDirect(sqlq);
>       PQConnection1.ExecuteDirect('Commit Work;');
>       PQConnection1.Connected:=False;
> 
> Then I have attempted to retrieve the enquiryreferencenumber using
> SQLQuery1 as follows:
>       SQLQuery1.SQL.Text:='SELECT enquiryreferencenumber FROM
> registration WHERE fname='''+fname.Text+''' AND
> sname='''+sname.Text+'''ORDER BY enquiryreferencenumber DESC LIMIT
> 1;';
>       SQLQuery1.Open;
>       enquiryreferencenumber.Text:=SQLQuery1.FieldByName('enquiryreferencenumber').AsString;
>       SQLQuery1.Close;
> 
> This gives me the following error:
>      SQLQuery1: Field not Found: "enquiryreferencenumber"
> 
> Can anyone help?

No idea. But you could try to set the fieldname between double-quotes
(") But that should only be an issue when you also did that while you
created the database.

You could also try SQLQuery1.Fields[0].AsString; as you did in your
first example.

And which version of fpc are you using? It could be a releaf if you use
a recent 2.2.1 snapshot.

Joost.




More information about the Lazarus mailing list