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);
精彩评论