469,306 Members | 2,463 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,306 developers. It's quick & easy.

Dataset.ReadXml() - "Input string was not in a correct format" with decimal fields

muaddubby
Hi

I'm running into a scenario with a DataSet that has a schema loaded into it, tries to then load data (that matches the schema), and fails with a "Input string was not in a correct format" exception because the decimal field in one of the incoming fields is written in exponential form.

I've looked at generating the XML with a fully written decimal value (as opposed to using exponential notation) but that's an issue because right now the XML is the serialized output of a class with a public Double field (we're just using the [serializable] attribute). This class is auto generated and would be a huge pain to change (e.g. to implement ISerializable and then format each field in a customized manner).

I've tried to find a way for the DataSet to read exponential notation into decimal fields and could not. MS apparently had reported something this as a bug in 2005 (http://support.microsoft.com/kb/321542), but it isn't exactly the same thing.

Any ideas on how to get a dataset.readxml to accept exponential notation as a valid decimal value?

Thx.
Nov 17 '08 #1
9 7700
balabaster
797 Expert 512MB
Check this out:

http://support.microsoft.com/default...en-us%3B321542
Nov 17 '08 #2
Thx, but that's the exact same article I mentioned in my post :)
Nov 18 '08 #3
balabaster
797 Expert 512MB
Thx, but that's the exact same article I mentioned in my post :)
I'm missing the point then... this demonstrates how to get your reader application to read the exponent/scientific notation as a string and then convert it using Decimal.Parse which will read scientific notation.

It doesn't require the class generating the XML to be modified...it just attaches a schema to the reader that tells it to read the decimals as string which can then be parsed at a later point in the code...

Which is what you're attempting to do, no?
Nov 18 '08 #4
I had understood this patch to be a fix to the Write() method of the dataset so that it no longer outputs exponential notation for decimals fields. You're saying this patch fixes the Read() instead, so that it can read both regular and exponential notation?

If the patch is indeed on the Write(), then it's useless because my XML is not generated by a DataSet.

I had not had a chance to install this patch and test it out because that involves IT, and therefore quite a bit of time...
Nov 18 '08 #5
balabaster
797 Expert 512MB
Read further down the article to the workaround... read step 3 very carefully. You're not required to install anything to implement the workaround. You'd only need ITs involvement if you were to install the hotfix directly...
Nov 18 '08 #6
Ok, yes. There is that workaround. I could not use that either, though, because the schema is used for several other tools, and they would all have to be changed in order to accomodate this decimal-as-a-string badaid. Really sucks.

Thx for pointing it out, though.
Nov 18 '08 #7
balabaster
797 Expert 512MB
Ok, yes. There is that workaround. I could not use that either, though, because the schema is used for several other tools, and they would all have to be changed in order to accomodate this decimal-as-a-string badaid. Really sucks.

Thx for pointing it out, though.
The only other way I can think of then is to import the XML file directly and parse it yourself which as you're already thinking is a pain in the butt...

LINQ to XML makes it about as painless as it can be without following the route you were already following - but it's still going to require some effort sadly. (and this assumes you're running .NET 3.0/3.5 - if you're on a lower version, you've gotta do it long hand I'm afraid)

Attach a sample XML doc to this thread and maybe someone can figure out something simple to get you unstuck - include some of the awkward scientific items.
Nov 18 '08 #8
Thx for the back-n-forth balabaster. In the end I ended up having to change the schema so that the public properties exposed as Double are now exposed as Decimal. This has the effect of serializing them as fully written out numbers instead of using exponential notation, and the DataSet now has no issue in reading in the XML.

It wasn't as painful a change as I thought it would be, but it would have been nice to have been spared all the headaches, hair loss, weight gain, intravenous coffee drips and head-on-wall bashings that this bug brought upon me.

Thx again.
Nov 19 '08 #9
balabaster
797 Expert 512MB
Thx for the back-n-forth balabaster. In the end I ended up having to change the schema so that the public properties exposed as Double are now exposed as Decimal. This has the effect of serializing them as fully written out numbers instead of using exponential notation, and the DataSet now has no issue in reading in the XML.

It wasn't as painful a change as I thought it would be, but it would have been nice to have been spared all the headaches, hair loss, weight gain, intravenous coffee drips and head-on-wall bashings that this bug brought upon me.

Thx again.
What doesn't kill us makes us better programmers ;)
Nov 19 '08 #10

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by phmyhn | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.