Question on Numeric Formating...

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.
 
M

Marina

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.
 
M

Manuel Canas

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.
 
G

Guest

Try this:
txtTestPrice.Text() = Ctype(drSQL.Item("Price"), Decimal).ToString("c", us)
 
B

bclegg

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top