I am creating an ATM application for a project. I am using VB.net to update the balance on MS access to a new balance to reflect the actions of the withdraw function on the application. Currently the new balance appears in the 'txtNewBalance' however it doesn't update on the database itself and in-turn can't be used on a separate deposit page as the original balance appears and not the updated balance after withdrawal of some of the balance. The following is my code:
Public Class frmWithdraw
Dim objConnection As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=ATM2.accdb")
Dim objAccountDA As New OleDb.OleDbDataAdapter("Select * from tblAccount", objConnection)
Dim objAccountCB As New OleDb.OleDbCommandBuilder(objAccountDA)
Dim AccountDataSet As New DataSet()
Public Sub StoreDetails()
Dim objRow As DataRow
objRow = AccountDataSet.Tables("tblAccount").Rows.Find("AccounNum")
objRow.Item("AccountNum") = txtAccountNum.Text
objRow.Item("AccountBalance") = txtBalance.Text
End Sub
Public Sub Retrieve()
objAccountDA.FillSchema(AccountDataSet, SchemaType.Source, "tblAccount")
objAccountDA.Fill(AccountDataSet, "tblAccount")
txtAccountNum.Text = frmLogin.EmployeeNO
FillAccountDetails()
'FillUserDetails()
End Sub
Private Sub frmWithdraw_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'ATM2DataSet.tblAccount' table. You can move, or remove it, as needed.
' Me.TblAccountTableAdapter.Fill(Me.ATM2DataSet.tblAccount)
Retrieve()
End Sub
Public Sub FillAccountDetails()
Dim objRow As DataRow
objRow = AccountDataSet.Tables("tblAccount").Rows.Find(txtAccountNum.Text.ToString)
txtBalance.Text = objRow.Item("Balance").ToString
End Sub
Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click
Me.Hide()
frmMain.Show()
End Sub
Private Sub btnWithdraw_Click(sender As Object, e As EventArgs) Handles btnWithdraw.Click
If txtOutput.Text = "" Or txtOutput.Text = "0" Or txtOutput.Text >= 300 Then
MessageBox.Show("Invalid amount")
txtOutput.Clear()
End If
txtNewBal.Text = Val(txtBalance.Text) - Val(txtOutput.Text)
objAccountDA.Update(AccountDataSet, "tblAccount")
AccountDataSet.AcceptChanges()
Dim objCurrentRow As DataRow
objCurrentRow = AccountDataSet.Tables("tblAccount").Rows.Find(txtAccountNum.Text.ToString)
objCurrentRow("Balance") = Val(txtNewBal.Text.ToString)
Retrieve()
MessageBox.Show("Withdrawal Confirmed")
Me.Hide()
frmMain.Show()
End Sub
Private Sub TblAccountBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs)
Me.Validate()
Me.TblAccountBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.ATM2DataSet)
End Sub
Private Sub btn20_Click(sender As Object, e As EventArgs) Handles btn20.Click
txtOutput.Text = 20 * numAmount.Text
End Sub
Private Sub btn40_Click(sender As Object, e As EventArgs) Handles btn40.Click
txtOutput.Text = 40 * numAmount.Text
End Sub
Private Sub btn60_Click(sender As Object, e As EventArgs) Handles btn60.Click
txtOutput.Text = 60 * numAmount.Text
End Sub
Private Sub btn80_Click(sender As Object, e As EventArgs) Handles btn80.Click
txtOutput.Text = 80 * numAmount.Text
End Sub
Private Sub btn100_Click(sender As Object, e As EventArgs) Handles btn100.Click
txtOutput.Text = 100 * numAmount.Text
End Sub
Private Sub HelpToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles HelpToolStripMenuItem.Click
Me.Hide()
frmHelp.Show()
End Sub
End Class
Option Strict On
– preciousbetine