473,396 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Calculated value on textChanged event can't be updated to database

I have invoice form bound to a bindingsource and bindingnavigator. In the form I have unit price, quantity and total textboxes. The total textbox text property is set to total.text = quantity.text * unitprice.text in the textChanged event of both quantity and unitprice text boxes. The result is displayed in the total textbox. But when i hit save button on the bindingnavigator it is set to null and not saved to database.

The code on save button is
bindingsource.endEdit()
bindingsource.update()
When I used msgbox to see the value of total textbox before bindingsource.endEdit() it is the correct value. but after the code bindingsource.endEdit() it is null. I checked the databinding property and it is correct. What is the problem.
Jan 14 '10 #1

✓ answered by ashukite

i didn't solve this problem. but i deleted the total field from my databse because it is a calculated value. I added a column to my dataset and make its value an expression.

4 2676
tlhintoq
3,525 Expert 2GB
total.text = quantity.text * unitprice.text
You can't apply math operations to text. You need to convert the text to some flavor of numbers first, whether it be floats, ints or decimals. Otherwise you might as be trying to perform total.text = "Fred" * "Wilma" which will not equal "Pebbles".
Jan 14 '10 #2
the text box doesn't accept text. it is validated to accept numeric values only. Besides I tried this
total.text = convert.todecimal(quantity.text * unitprice.text) and the result I get on the msgbox is correct result. This is not the case.
Jan 14 '10 #3
i didn't solve this problem. but i deleted the total field from my databse because it is a calculated value. I added a column to my dataset and make its value an expression.
Jan 14 '10 #4
tlhintoq
3,525 Expert 2GB
the text box doesn't accept text. it is validated to accept numeric values only. Besides I tried this
total.text = convert.todecimal(quantity.text * unitprice.text) and the result I get on the msgbox is correct result. This is not the case
The fact that you limit the incoming text to just numbers doesn't change the fact that the .Text value of a textbox is not an numeric value but a string.
You have to convert each value to a decimal *THEN* you can multiply those numbers.
Expand|Select|Wrap|Line Numbers
  1. decimal NewValue = Convert.ToDecimal(quantity.text) * Convert.ToDecimal(unitprice.Text);
Jan 15 '10 #5

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

Similar topics

3
by: Fabrício de Novaes Kucinskis | last post by:
Hi all, I have a combobox control, in wich I put an autocomplete code. This code is in the TextChanged event, but when this event fires, the Text property isn't updated yet. For example, if...
0
by: AndyDunning | last post by:
Following the initial load of data into bound controls as my form loads , I want to detect when a user have changed the value of one of the Combo or text box fields etc This will allow me to test...
3
by: Jeremy Weiss | last post by:
I've got a temp table that contains the fields: amountowed, amountpaid, and balanced. I've got a form that shows this information and I've set it up so that when the amountpaid field is changed it...
1
by: douh | last post by:
I know that this is not the way, however I need to save certian calculated values so that they do not change over time, ie. new tax rates etc. This is for an invoice header and invoice subform. I...
4
by: Francesco | last post by:
Hi all, I am trying to make a UserControl with a TextBox in it. I have to publish the TextChanged event of the inner TextBox, but I have some trouble. If I declare : public event EventHandler...
1
by: Samuel Chan | last post by:
I used the textchanged event of textbox and set the autopostback property to true. The textchanged event should fire when the content of the textbox is changed and user tab out of the textbox...
8
by: Dan Keeley | last post by:
Hi, I have a dataset which is used to populate my datagrid something like this: My question is, how do I add a caluclated display column to the datagrid? It will be based on ScoreCardScore... ...
1
by: Manish | last post by:
Hello Everyone I am having weird problem in my datagrid bounded to datatable. My datatable is populated from SQLServer database. DataGrid has Calculated column Week% and Calculated record, SPLH....
0
by: jarrett.roberts | last post by:
I have created a webform that allows the user to complete the form in three steps and allows a back and next button to allow easy navigation between these different forms. If they go back, I save...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
marktang
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
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,...
0
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...
0
tracyyun
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...
0
agi2029
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.