简体   繁体   中英

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

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);

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

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM