Question General Error - overflow

tolu

New member
Joined
Jan 20, 2011
Messages
2
Programming Experience
5-10
i new using the vb.net 2008 and i'm working on a payroll application to save entries in a form to an access database. However when i click on the save button (created on the form) to save the form entries into the access database table created, it comes up with the overflow error (when debugging in the IDE). I have checked the data types to find out if there is a conflict (data types used are text, number, currency and date/time for the fields) but i don't seem to see any. Can somebody please give a clue regarding what i'm doing wrong.

The code snippet that the save button executes is as follows --


Private Sub AddPaySlip()
Try
'Dim dbCommand As OleDbCommand
Dim DBConn As OleDbConnection
Dim DBInsert As New OleDbCommand

DBConn = New OleDbConnection(ACCESS_CONNECTION_STRING)

DBInsert.CommandText = "INSERT INTO Payroll VALUES (" _
& "'" & dtpFromPay.Text & "', " _
& "'" & dtpToPay.Text & "', " _
& "'" & strSelectedAssignCode & "', " _
& "'" & txtWorkDays.Text & "', " _
& "'" & txtBasic.Text & "', " _
& "'" & txtRent.Text & "', " _
& "'" & txtPA.Text & "', " _
& "'" & txtMeal.Text & "', " _
& "'" & txtContis.Text & "', " _
& "'" & txtLevel.Text & "', " _
& "'" & txtBank.Text & "', " _
& "'" & txtOVT.Text & "', " _
& "'" & txtDesignation.Text & "', " _
& "'" & txtResearch.Text & "', " _
& "'" & txtDriver.Text & "', " _
& "'" & txtFieldTrip.Text & "', " _
& "'" & txtShift.Text & "', " _
& "'" & txtFurniture.Text & "', " _
& "'" & txtMedical.Text & "', " _
& "'" & txtUtility.Text & "', " _
& "'" & txtPCSource.Text & "', " _
& "'" & txtLeave.Text & "', " _
& "'" & txtArrears.Text & "', " _
& "'" & txtOthers1.Text & "', " _
& "'" & txtOthers2.Text & "', " _
& "'" & txtTaxes.Text & "', " _
& "'" & txtXmas.Text & "', " _
& "'" & txtNHF.Text & "', " _
& "'" & txtSurcharge.Text & "', " _
& "'" & txtMisc.Text & "', " _
& "'" & txtPensions.Text & "', " _
& "'" & txtHousing.Text & "', " _
& "'" & txtNetIncome.Text & "', " _
& "'" & txtGross.Text & "', " _
& "'" & txtTotalDed.Text & "', " _
& "'" & txtCarLoan.Text & "', " _
& "'" & txtCTSL.Text & "', " _
& "'" & txtSalaryAdv.Text & "', " _
& "'" & txtUnion.Text & "', " _
& "'" & DateTime.Now.ToString & "')"


I will so much appreciate replies as soon as possible. Thanks.
 
whoah, please google 'using sql parameters in vb.net', it will prevent errors such as yours and make your code much cleaner.
 
DBInsert.CommandText = "INSERT INTO Payroll VALUES (" _
& "'" & dtpFromPay.Text & "', " _
& "'" & dtpToPay.Text & "', " _
& "'" & strSelectedAssignCode & "', " _
& "'" & txtWorkDays.Text & "', " _
& "'" & txtBasic.Text & "', " _
& "'" & txtRent.Text & "', " _
& "'" & txtPA.Text & "', " _
& "'" & txtMeal.Text & "', " _
& "'" & txtContis.Text & "', " _
& "'" & txtLevel.Text & "', " _
& "'" & txtBank.Text & "', " _
& "'" & txtOVT.Text & "', " _
& "'" & txtDesignation.Text & "', " _
& "'" & txtResearch.Text & "', " _
& "'" & txtDriver.Text & "', " _
& "'" & txtFieldTrip.Text & "', " _
& "'" & txtShift.Text & "', " _
& "'" & txtFurniture.Text & "', " _
& "'" & txtMedical.Text & "', " _
& "'" & txtUtility.Text & "', " _
& "'" & txtPCSource.Text & "', " _
& "'" & txtLeave.Text & "', " _
& "'" & txtArrears.Text & "', " _
& "'" & txtOthers1.Text & "', " _
& "'" & txtOthers2.Text & "', " _
& "'" & txtTaxes.Text & "', " _
& "'" & txtXmas.Text & "', " _
& "'" & txtNHF.Text & "', " _
& "'" & txtSurcharge.Text & "', " _
& "'" & txtMisc.Text & "', " _
& "'" & txtPensions.Text & "', " _
& "'" & txtHousing.Text & "', " _
& "'" & txtNetIncome.Text & "', " _
& "'" & txtGross.Text & "', " _
& "'" & txtTotalDed.Text & "', " _
& "'" & txtCarLoan.Text & "', " _
& "'" & txtCTSL.Text & "', " _
& "'" & txtSalaryAdv.Text & "', " _
& "'" & txtUnion.Text & "', " _
& "'" & DateTime.Now.ToString & "')"


I will so much appreciate replies as soon as possible. Thanks.

This not the way to write an sql statement. Im sure even you have a problem reading and understanding it.
 
If you would care to read the DW3 link in my signature, section "Creating a Simple Daa App" and learn about the ways Microsoft say you should work with databases in your code, that would be marvellous, thanks!
 

Latest posts

Back
Top