the following are the codes. I am ONLY allowed to withdraw/subtract a value ONLY IF the balance amount(after subtracting) in the database is above certain amount . Example: If balance amount in database >= 100 after subtracting, then subtraction successful. Else If balance amount in database <= 100, then subtraction denied.
If IsNumeric(accountnotxt.Text.ToString) And IsNumeric(amounttxt.Text.ToString) = True Then
cmdsearch.CommandText = "SELECT * FROM [Current_Account] WHERE [AccountNo] = " & accountnotxt.Text
cmdupdate.CommandType = CommandType.Text
cmdsearch.Connection = cnnoledb
Dim read As OleDbDataReader = cmdsearch.ExecuteReader()
Dim withdrawamt As Decimal
withdrawamt = withdrawamt - amounttxt.Text >= 100
If read.Read = True Then withdrawamt = read(2).ToString ' this is the column of Amount in database
If read.Read = True Then
withdrawamt = read(2).ToString
cmdupdate.CommandText = "UPDATE [Current_Account] SET [Amount] = " & withdrawamt & " WHERE [AccountNo] =" & accountnotxt.Text.ToString & ";"
cmdupdate.CommandType = CommandType.Text
cmdupdate.Connection = cnnoledb
cmdupdate.ExecuteNonQuery()
MsgBox(" Successfully withdrawn from account " + accountnotxt.Text)
Else
MsgBox("Minimum of 100 must be available in your account.")
End If
read.Close()
Else
MsgBox(" Please enter valid information. ")
The program did not crash and no changes in the database than the MsgBox that showed up.
Thanks in advance !
Aucun commentaire:
Enregistrer un commentaire