Scientific Notation In Textbox

G

Greg

I am working on an application that requires working with numbers in
scientific notation. I am using SqlServer as the database and I have
created strongly typed data adapters and datasets. The numbers are
defined as numeric in the SqlServer Database and are bound to text
boxes in the app. In the dataset's xml these numbers are defined as
decimal. I am using the binding method Format to display the data in
scientific notation and Parse to convert back to numeric before posting

to the database. This all works just fine until you try to enter
scientific notation into the text box directly. In other words,
entering 1230000000 is OK and parses to 1.23e+009 and is posted to the
DB as 1230000000. But if you try to enter 1.23e+009 into the text box
directly it gets rejected (blanked out) or reverts to the previous
entry.

I have found this to be normal text box behavior when using
strongly typed datasets where you try to enter a value that is invalid
for the data type specified in the dataset. For example, entering an
invalid date into a text box bound to a date column does the same
thing. This behavior is initiated before any validation events have a
chance of firing and seems to be something I cannot control.

So, my question is, can anybody tell me how I can
set up the text boxes to accept direct input of scientific notation so
the users can enter 1.23e9 or 1.23e+9 or 1.23e+009 or 1230000000?

What is most irritating is that in the same app I have datagrids with
datagrid text boxes that accept the same scientific numbers and have no

issue formatting or parsing these numbers without any special handling
or method calls. So in a datagrid text box I can enter 1.23e9, 1.23e+9,

1230000000 and it parses and posts it all just fine. This type of
inconsistant behavior drives me and the users crazy.
 
D

Daniel

I didnt read all you wrote but noticed no mention of SqlParameter......look
up SqlParamter and pass in your values as SqlParameters to the db.

Issues with the textbox itself reformatting i am not sure, i would have
thought it would read it as a string and not format at all keeping the '+'
signs? You sure the text box is doing this?
 
G

Greg

I'm sure. I can use Format and Parse to display the scientific notation
and parse to numeric for the DB. But if I enter scientific notation
directly into the textbox it rejects and and reverts to it's previous
value.

In other words,
entering 1230000000 is OK and parses to 1.23e+009 and is posted to the
DB as 1230000000. But if you try to enter 1.23e+009 into the text box
directly it gets rejected (blanked out) or reverts to the previous
entry.
 

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