Question on Numeric Formating...

  • Thread starter Thread starter Manuel Canas
  • Start date Start date
M

Manuel Canas

Hi there,

I'm building an application with ADO.NET and VB.NET.
This is the issue that I have right now;
I'm using this code with a data reader to populate a form from a database
(sqlServer, MSDE)

*****************
Dim us as New CultureInfo("en-US")
txtTestPrice.Text() = drSQL.Item("Price").ToString()
******************

I'm trying to convert this string into a curreny format type and I'm not
having any luck on this one.
I'm importing the System.Globalization namespace.
it gives an error when I do this

txtTestPrice.Text() = drSQL.Item("Price").ToString("c", us)
Error - Public Overridable Function ToString() As String' has no parameters
and it's return type cannot be indexed.

Can anybody out there help out on this one? Please!
Thanks very much for your help on this matter.
Manny.
 
That is because a datareader's Item property returns an obj. And the object
class does not have a ToString function with any parameters. Hence, you need
to either use the GetDecimal method (or whatever is appropriate) and then
call ToString on that, or cast what you get from Item to a Decimal, and then
call ToString.
 
Hi Marina,

Could you give you kind advice on code? I confess, I'm new to the .net
technology and I just know how to instantiate the getdecimal or cast the
item to decimal and the call tostring on that.

Thanks for your kind help.

Manny.
 
Hi Manual,
Are you sure that the dr.item("Price") is retrieving a numeric field?
what happens if you
txtTestPrice.Text()=ctype(dr.item("Price"),double).toString("c", us)
regards
Bob
 
Back
Top