-1

I have textboxes on my form using for txtDueAmount, txtPaidamount, txtDiscount and txtNetBalance. Every time I want that as I press the save button so all the floating point values of textboxes turns into integer and if any value is like 30.5 so it also converters it into 31.

This is my insert query:

Insert("SaleMaster", "SaleID, SaleTotalAmount, SalePaidAmount, SaleDiscount,
SaleNetBalance, SaleDate", txtSaleID.Text & ", " & txtSaleDueAmount.Text & 
", " & txtSalePaidAmount.Text & ", " & txtSaleDiscount.Text & ", " & 
txtSaleNetBal.Text & ", '" & dtpSale.Value.Date & "'")

Please help me with this.

Ňɏssa Pøngjǣrdenlarp
  • 38,411
  • 12
  • 59
  • 178
user87
  • 27
  • 5
  • 1
    What is the type of the DB columns? By the way, this looks ripe for SQL injection attacks. I would be much better to use SQL parameters. – Steven Doggart Jan 27 '14 at 15:10
  • you have no code to convert text to numeric at all, let alone rounding. Also meet [Little Bobby Tables](http://stackoverflow.com/q/332365/1070452) – Ňɏssa Pøngjǣrdenlarp Jan 27 '14 at 15:12
  • Db column type is integer – user87 Jan 27 '14 at 15:15
  • Integer doesn't support fractions, so it's the DB engine that's doing the rounding/truncation. You need to use a column type which supports fractions/floating point values. – Steven Doggart Jan 27 '14 at 15:18
  • Doggart, you mean numeric or Float? Which one i am suppose to use? – user87 Jan 27 '14 at 15:32
  • Well, that all depends on the database engine. Is this SQL Server, Jet DB, something else? – Steven Doggart Jan 27 '14 at 15:40
  • I strongly suggest you change your approach at saving. You should use SQL Parameters. – the_lotus Jan 27 '14 at 16:51
  • @The-Lotus, I've using parameterized queries for long time but i came across with a problem where parameterized query wasn't working. Thats why i changed the way to straight query. It wasn't working with my function. – user87 Jan 28 '14 at 01:17

1 Answers1

0

Just covert to integer using CInt(txtbox.Text)

You should also validate that the textboxs only have numeric values.

Mych
  • 2,527
  • 4
  • 36
  • 65
  • Also you may end up due to rounding that your figures do not add up. – Mych Jan 27 '14 at 15:14
  • What is that mean Mych, that ""Also you may end up due to rounding that your figures do not add up."". – user87 Jan 27 '14 at 15:28
  • he is saying that if you round the values used to produce a sum (TotalSale), then they will no longer add up. In most cases you will want a float for those db columns so you do not have to round. Do that after you switch to parameters – Ňɏssa Pøngjǣrdenlarp Jan 27 '14 at 15:31
  • Yes... as Plutonix says.. Eg. 10.7 + 8.9 + 13.9 = 33.5 yet 10 + 8 +13 = 31 – Mych Jan 27 '14 at 15:36
  • Dear plutonix, so should i simply change the DB column types for these fields?? – user87 Jan 27 '14 at 15:38
  • I would... You can always restrict number of decimals if required. – Mych Jan 27 '14 at 15:43