Correct way of retrieving a longint field from a SQL Server table in Delphi 5

779 views Asked by At

I have a field with value -7590730850027557904 in SQL Server 2005 and I am retrieving it through ADO in Delphi 5 but what I retrieved was 7590730850027557904 - the negative sign was omitted. What is the correct way of retrieving longint values from SQL Server to Delphi 5?

Here is my code

  with DataSet do
  begin
    Connection := Conn;
    CommandText := 'SELECT * FROM CUSTOMERSLIST';
    Open;
  end;
  ShowMessage(DataSet.FieldByName('SID').AsString);
2

There are 2 answers

0
rajeemcariazo On BEST ANSWER

Thanks to my colleague. The solution is to covert bigint to string as you query from the database.

 with DataSet do
  begin
    Connection := Conn;
    CommandText := 'SELECT CASST(SID AS VARCHAR(50)) AS SID FROM CUSTOMERSLIST';
    Open;
  end;
  ShowMessage(DataSet.FieldByName('SID').AsString);
0
SimaWB On

SQL Server has bigint type.
It's from -2^63 (-9,223,372,036,854,775,808) through 2^63-1 (9,223,372,036,854,775,807).
Equivalent Int64 in Delphi