1 (edited by AD1408 2017-11-19 21:21:37)

Topic: SQL .Value decimals

I get an error "Could not convert variant of type (UnicodeString) into type (Double)"


I'm trying to get details of a currency field with decimals displayed on form viaSQL.
To get the currency decimals using:

FORM2.edPriceType01.Value := SQLExecute('SELECT PriceType01 FROM Product WHERE id='+FORM2.tgProducts.sqlValue);

Instead of

FORM2.edPriceType01.Text := SQLExecute('SELECT PriceType01 FROM Product WHERE id='+inttostr(FORM2.tgProducts.dbitemid));

All OK, until I add clear fields script for product form. I need to clear type details when different product type.


Please see the attached sample project.


----------------------------------------------------------------
EDIT:

After some trial and error I found that; instead of clearing fields, making them 0.00 eliminates the above mentioned error message.

Doesn't work:

frmProduct.edPriceType02.Clear;

Works:

frmProduct.edPriceType02.Value := 0.00;

If the above approach is incorrect please let me know.

Post's attachments

Attachment icon SQLvalue Decimals.zip 10.46 kb, 376 downloads since 2017-11-19 

Adam
God... please help me become the person my dog thinks I am.

Re: SQL .Value decimals

Problem in the NULL values, null value can't be converted to double, how to fix

procedure FORM2_tgProducts_OnCellClick (Sender: TObject; ACol, ARow: Integer);
begin
  FORM2.edProdName.Text := SQLExecute('SELECT name FROM Product WHERE id='+inttostr(FORM2.tgProducts.dbitemid));
  FORM2.edProdType.Text := SQLExecute('SELECT typeValue FROM Product WHERE id='+inttostr(FORM2.tgProducts.dbitemid));
  FORM2.edProdUnitPrice.Value := SQLExecute('SELECT unitPrice FROM Product WHERE id='+FORM2.tgProducts.sqlValue);

  FORM2.edPriceType01.Value := SQLExecute('SELECT IFNULL(PriceType01, 0) FROM Product WHERE id='+FORM2.tgProducts.sqlValue);
  FORM2.edPriceType02.Value := SQLExecute('SELECT IFNULL(PriceType02, 0) FROM Product WHERE id='+FORM2.tgProducts.sqlValue);
  FORM2.edPriceType03.Value := SQLExecute('SELECT IFNULL(PriceType03, 0) FROM Product WHERE id='+FORM2.tgProducts.sqlValue);
end;
Dmitry.

Re: SQL .Value decimals

Hi Dmitry,


Thank you very much....
Truly appreciated..................

Adam
God... please help me become the person my dog thinks I am.