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 69825
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: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
|
by: Arjunsri |
last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
|
by: Matthew3360 |
last post by:
Hi,
I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
|
by: Oralloy |
last post by:
Hello Folks,
I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA.
My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
|
by: Carina712 |
last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
|
by: Ricardo de Mila |
last post by:
Dear people, good afternoon...
I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control.
Than I need to discover what...
|
by: Johno34 |
last post by:
I have this click event on my form. It speaks to a Datasheet Subform
Private Sub Command260_Click()
Dim r As DAO.Recordset
Set r = Form_frmABCD.Form.RecordsetClone
r.MoveFirst
Do
If...
|
by: ezappsrUS |
last post by:
Hi,
I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
| | |