sudani1969
Member
- Joined
- Sep 25, 2009
- Messages
- 13
- Programming Experience
- Beginner
hi Guys this is my first post hopefully it not a repeat if it is i do appolgize for time wasting
i try to create a windows form that act something smilar to a cash machine i managed to enter a mount with my first button then my second button is for withdrawing money it checks the amount in the text amount if it is higher than the amount the small dat hold in the amount it will throw an error message if it is less or equal it write the amount in the text box
my goal is to deduct that amount in the textbox amount from the amount already at the data base COULD ANY ONE DIRECT ME AND WHERE I'M GOING WRONG THE CODE IS BELOW
thanks in advance
Imports System.Data
Imports System.Data.SqlClient
Public Class Form1
Dim con As New SqlConnection("Data Source = bedroom\vista; initial catalog = Volunteers; integrated security = true")
Dim DtRd As SqlDataReader
Private Sub txtDeposit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeposit.Click
con.Open()
Dim insert As New SqlCommand(" Insert into [Balance] ([Amount]) Values(@amount)", con)
insert.Parameters.AddWithValue("@amount", txtAmount.Text)
Dim RowId As Integer = insert.ExecuteScalar()
End Sub
Private Sub btnWithdraw_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWithdraw.Click
con.Open()
Dim balance As Double
Dim cmd As New SqlCommand
cmd.Connection = con
cmd.CommandText = "Select Amount from balance"
DtRd = cmd.ExecuteReader()
While DtRd.Read
If txtAmount.Text > DtRd.Item(0).ToString Then
MsgBox("There is not enough sufficent fund in your account", MsgBoxStyle.Critical)
ElseIf txtAmount.Text <> DtRd.Item(0).ToString Then
MsgBox("The amount of " + txtAmount.Text + " will be deducted from your account", MsgBoxStyle.Information)
' DtRd.Close()
End If
balance = DtRd.Read
MainCon.UpdateCommand.CommandText = "UPDATE balance SET [Amount]'" & txtAmount.Text - balance & "'"
MainCon.UpdateCommand.ExecuteNonQuery()
End While
'DtRd.Close()
End Sub
End Class