Furma94 Furma94 - 6 months ago 29
SQL Question

Delphi XE7 MultiDevice SQL Error TIMESTAMP Ret. Field

I've an

SQLTIMESTAMP
binded (SQL output of query from datamodule)


(On live bindings) -> BindVIsually TTMFSMXGRID.


When I open the query, the field is correctly filled in the grid (EX:
06/05/2016
, etc)

But when I try to take the
Cell[x,y]
as
StringToSqltimestamp
it come back in a different format (
WRONG FORMAT
). And I am trying to use field for a query so it make me an error (
EOF
) because don't find anything in that date.

dm1.UpdMsg.ParamByName('data').AsSQLTimeStamp:=StrToSQLTimeStamp(GrRec.Cells[1,GrRec.FocusedCell.Row]);


Any idea about how to solve it?

Answer

Like other date/time formatting functions, StrToSqlTimeStamp() by default uses formatting criteria based on the current system locale. If that does not match what you need (for example, maybe the day and month are swapped), you can use the overloaded version that accepts a TFormatSettings as input so you can customize it.

var
  Fmt: TFormatSettings;
begin
  // Get default settings first...
  Fmt := TFormatSettings.Create;

  // customize Fmt as needed...
  Fmt.ShortDateFormat := 'dd/mm/yyyy';
  Fmt.DateSeparator := '/';

  // not convert...
  dm1.UpdMsg.ParamByName('data').AsSQLTimeStamp := StrToSQLTimeStamp(GrRec.Cells[1,GrRec.FocusedCell.Row], Fmt);
end;
Comments