[DUG] interesting issue in .NET
Jeremy Coulter
vss at vss.co.nz
Fri Jan 5 12:31:27 NZDT 2007
Yeah I knew about the system.String.Format("{0:c}", rdr[Amount]) way of
doing it, but was not sure WHY I was getting the error.....still getting to
grips with .NET. Did do a course 2 years ago, but obviously forgotten a lot
:-)
Jeremy
-----Original Message-----
From: delphi-bounces at ns3.123.co.nz [mailto:delphi-bounces at ns3.123.co.nz] On
Behalf Of jamessugrue at xtra.co.nz
Sent: 5 January 2007 12:01
To: NZ Borland Developers Group - Delphi List
Subject: Re: [DUG] interesting issue in .NET
I am assuming rdr is a DataReader. It returns an object. You will have to
explicitly convert it using System.Convert.ToDecimal, ToSingle - whatever
you want
I'm guessing that .NET thinks object is too ambiguous to use a boxing cast.
BTW if you want to convert to String you could try (should work doing OTOH)
string s = String.Format("{0:c}", rdr[Amount]);
---- Jeremy Coulter <vss at vss.co.nz> wrote:
> Hi all.
> I have come across an issue that I am not sure about in .NET
>
> I have a value being returned from a stored procedure. Tha value is a
> decimal value, i.e. 511.34
>
> But when I do this :- system.Double(rdr['AMOUNT']).ToString('C');
> (converting it to a currency format)
>
> I get an error "Specified cast is not valid" yet I know there IS a
value
> being passed in, and it IS a double.
>
> anyone know WHY?
>
> Thanks, Jeremy
>
> --
> No virus found in this outgoing message.
> Checked by AVG Free Edition.
> Version: 7.5.432 / Virus Database: 268.16.5/616 - Release Date:
> 04/01/2007
> 13:34
>
_______________________________________________
Delphi mailing list
Delphi at ns3.123.co.nz
http://ns3.123.co.nz/mailman/listinfo/delphi
--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.16.5/616 - Release Date: 04/01/2007
13:34
--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.16.5/616 - Release Date: 04/01/2007
13:34
More information about the Delphi
mailing list