Hello Folks,
I am bring backa data reader dr from the database/
So I have a number of fields such as dr["ExtendedPr ice"]
To put this in a table I use "<td>" + dr["ExtendedPr ice"].ToString()
+ "</td>"
But I want to format the number as mentioned in the subject line.
It won't work...tells me that ToString accepts 1 argument.
What am I doing wrong?
Thanks-in-Advance,
Bob Sweeney 5 70421
At the time, you only have an object; to use this overload you either
need to know what the datatype is (int, decimal, float, double, etc -
I'm guessing double, so ((double)dr["ExtendedPr ice"]).ToString(...) ),
or (if you can't predict the type, but think it should work) use the
IFormattable interface (i.e.
((IFormattable) dr["ExtendedPr ice"]).ToString(...) )
Marc
"Bob" <Go****@Yahoo.C omwrote in message
news:11******** **************@ l77g2000hsb.goo glegroups.com.. .
What am I doing wrong?
Not converting the object from the DataReader into something which can have
text formatting applied to it...
"<td>" + Convert.ToDecim al(dr["ExtendedPr ice"]).ToString("#,# #0.00") +
"</td>"
-- http://www.markrae.net
Kick myself!! Prices as double! Sheesh! I meant decimal....
the shame...
Marc
On May 10, 1:17 pm, Bob <Go1...@Yahoo.C omwrote:
Hello Folks,
I am bring backa data reader dr from the database/
So I have a number of fields such as dr["ExtendedPr ice"]
To put this in a table I use "<td>" + dr["ExtendedPr ice"].ToString()
+ "</td>"
But I want to format the number as mentioned in the subject line.
It won't work...tells me that ToString accepts 1 argument.
What am I doing wrong?
Thanks-in-Advance,
Bob Sweeney
Hey Bob,
The DataRow index operator returns an object. So the ToString method
is the ToString method if the object returned.
If you need to format the returned object, use String.Format()
overloads.
For instance, to format the price in currency use
String.Format(" {0:C}", dr["ExtendedPr ice"]);
Refer to http://msdn2.microsoft.com/en-us/lib...ng.format.aspx
for further details and advanced formatting.
Cheers,
Moty
On May 10, 1:37 pm, Moty Michaely <Moty...@gmail. comwrote:
On May 10, 1:17 pm, Bob <Go1...@Yahoo.C omwrote:
Hello Folks,
I am bring backa data reader dr from the database/
So I have a number of fields such as dr["ExtendedPr ice"]
To put this in a table I use "<td>" + dr["ExtendedPr ice"].ToString()
+ "</td>"
But I want to format the number as mentioned in the subject line.
It won't work...tells me that ToString accepts 1 argument.
What am I doing wrong?
Thanks-in-Advance,
Bob Sweeney
Hey Bob,
The DataRow index operator returns an object. So the ToString method
is the ToString method if the object returned.
If you need to format the returned object, use String.Format()
overloads.
For instance, to format the price in currency use
String.Format(" {0:C}", dr["ExtendedPr ice"]);
Refer tohttp://msdn2.microsoft .com/en-us/library/system.string.f ormat.aspx
for further details and advanced formatting.
Cheers,
Moty
Of course, you can always use unboxing as my colleagues just
suggested :)
Moty This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: steve |
last post by:
I am quite frustrated with php’s include, as I have spent a ton of
time on it already... anyone can tell me why it was designed like this
(or something I don’t get)?
The path in include is relative NOT to the immediate script that is
including it, but is relative to the top-level calling script.
In practice, this means that you have to constantly worry and adjust
paths in includes, based on the startup scripts that call these...
|
by: PK9 |
last post by:
I have a string variable that holds the equivalent of a DateTime value. I
pulled this datetime from the database and I want to strip off the time
portion before displaying to the user.
I am using C#
eg.
- String variable "strMyDate" holds the value "1/1/2005 12:00:00 AM" from
the database.
- I do not care about the time portion, I only want "1/1/2005" for display.
|
by: geskerrett |
last post by:
We are working on a project to decipher a record structure of an old
accounting system that originates from the late80's mid-90's.
We have come across a number format that appears to be a "float" but
doesn't match any of the more standard implementations.
so we are hoping this is a recognizable number storage format with an
identifiable name AND pre-built conversion method
similiar to the "struct" modules available in python.
Here is...
|
by: - Steve - |
last post by:
I've been given a school assignment and while everything else is easy
there's one topic I'm completley lost on.
I've been given an ASCII file that looks like this. During start-up, the
program needs to read an ASCII data file of inventory records and build an
appropriate dynamic data structure using structs and pointers.
10112 MICROPROCESSOR 2100 2 B 000008.50 000012.50
10235 CHARACTER_PRINTER 4013 4 C 000995.00 001295.00
10450...
|
by: Tony |
last post by:
Hello
I am learning C# and encountered the following problem when I tried to figure out how to print
the string {0} in a Console window
The following piece of codes complied OK. But when I ran it, it failed
The codes are
using System
class Test
| |
by: Stimp |
last post by:
I want to output a number, say 20, as 20.00
i.e. I want to always have 2 decimal places
I don't want any currency information, therefore String.Format("{0:c}")
doesn't work for me.
Can't seem to find a way to do this. Any ideas?
Thanks,
|
by: Bob |
last post by:
Hello folks.
I use this formating but if the value in dr is a null it generates
an error
"Object cannot be cast from DBNull to other types."
Anybody know how I can deal with nulls?
Thanks,
|
by: buddyr |
last post by:
Hello I am working on time sheet form.
Whether I create fields in query = \60 & format( mod 60, "\00")
or Round((Table2.OUT-Table2.)*24,4) AS HOURS
When I try to add my totals in the fields to give me one Total- It only lets me if I have every field entered data into- And so If somebod is sick and does not fill in Tuesday IN and OUT
The total will not show up in my report.
any ideas
I tried notNull - maybe not in right place-- I have...
|
by: Imaginativeone |
last post by:
XML
<nodeAA>AA</nodeAA>
<nodeBB>BB</nodeBB>
<nodeCC>
<From>12/05</From>
<To>11/06</To>
<Months>12</Months>
<Amount>10.00</Amount>
CC
</nodeCC>
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| | |