Hello Folks,
I am bring backa data reader dr from the database/
So I have a number of fields such as dr["ExtendedPrice"]
To put this in a table I use "<td>" + dr["ExtendedPrice"].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 70257
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["ExtendedPrice"]).ToString(...)),
or (if you can't predict the type, but think it should work) use the
IFormattable interface (i.e.
((IFormattable)dr["ExtendedPrice"]).ToString(...))
Marc
"Bob" <Go****@Yahoo.Comwrote in message
news:11**********************@l77g2000hsb.googlegr oups.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.ToDecimal(dr["ExtendedPrice"]).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.Comwrote:
Hello Folks,
I am bring backa data reader dr from the database/
So I have a number of fields such as dr["ExtendedPrice"]
To put this in a table I use "<td>" + dr["ExtendedPrice"].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["ExtendedPrice"]);
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.Comwrote:
Hello Folks,
I am bring backa data reader dr from the database/
So I have a number of fields such as dr["ExtendedPrice"]
To put this in a table I use "<td>" + dr["ExtendedPrice"].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["ExtendedPrice"]);
Refer tohttp://msdn2.microsoft.com/en-us/library/system.string.format.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...
|
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...
|
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"...
|
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...
|
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...
|
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...
|
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?
...
|
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...
|
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>
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
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...
|
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,...
|
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...
| | |