mohsen.2 mohsen.2 - 4 months ago 8
MySQL Question

Unknown column ' ' in feild list

im trying to insert some information to mysql with pascl,

but when i run program i get eror

unknown column list 'mohsen' in feild list





this is my code



procedure TForm1.Button1Click(Sender: TObject);

var
aSQLText: string;
aSQLCommand: string;

namee:string;
family:string;
begin

namee:='mohsen';
family:='dolatshah';
``aSQLText:= 'INSERT INTO b_tbl(Name,Family) VALUES (%s,%s)';
aSQLCommand := Format(aSQLText,[namee,family]);

SQLConnector1.ExecuteDirect(aSQLCommand);
SQLTransaction1.Commit;

end;`
how can i solve this problem

Answer

It's because your

VALUES (%s,%s)

isn't surrounding the namee and family variable contents by quotes. Therefore, your back-end Sql engine thinks your mohsen is a column name, not a value.

Instead, use, e.g.

VALUES (''%s'',''%s'')

as in

  Namee := 'mohsen';
  Family := 'dolatshah';
  aSQLText:= 'INSERT INTO b_tbl(Name,Family) VALUES (''%s'',''%s'')';
  aSQLCommand := Format(aSQLText,[namee,family]);
Comments