Hello Sir,
i want to deduct some amount(i.e user input) from main loan taken by employee and remaining amount again come as balance loan amount and on nxt month again the some amount should deduct from balance loan amount.

my database is in ms-access and i use vb.net..

plz help......

Dani AI

Generated

Short answer: changing a label is only a UI change — it does not save anything to the Access database. To make the deduction permanent you must validate the user input, compute the new numeric balance in code, then persist that change with an SQL UPDATE or (better) insert a payment record and update the loan balance inside a transaction.

Recommended steps

  • Read the loan amount from the database into a numeric variable (Decimal), not into a Label and treated as the application state.
  • Validate the payment with Decimal.TryParse; reject non-numeric or negative values and handle overpayments according to your business rules.
  • Use a parameterized INSERT (Payments) and UPDATE (Loans) inside a transaction so the UI can be refreshed from the DB after commit. This gives you an audit trail and avoids race conditions.

Example pattern (VB.NET outline)

' parse payment
If Not Decimal.TryParse(txtPayment.Text, payment) Then Return

Using cn As New OleDbConnection(connString)
  cn.Open()
  Using tx = cn.BeginTransaction()
    ' insert payment record (audit)
    ' update loan balance using parameterized queries
    tx.Commit()
  End Using
End Using

' refresh displayed balance from DB

Notes and cautions

  • Use Decimal for money (not Double). Format only for display.
  • Don't use UI controls to hold state between operations. Always re-read or compute authoritative balance from DB.
  • For monthly automatic deductions store schedule data or create a background job that inserts payments and updates balances.
  • asked for code — the pattern above shows a safer approach. and were correct to ask what was tried: the problem here is lack of a database UPDATE/INSERT to persist the deduction.

Recommended Answers

All 6 Replies

What did you try? It sounds like the loans are going down and down :)

i created loan table, and i m fetching loan amount of each employee in a label to see d actual loan amount then i have one text box where user will insert amount and remaining amount on deduction come in another label as balance amount.

so what is the problem ?

i created loan table, and i m fetching loan amount of each employee in a label to see d actual loan amount then i have one text box where user will insert amount and remaining amount on deduction come in another label as balance amount.

Hi wenbnet,

You have a database for several employees (several records) and for each employee you you have several columns for the loan amount.

Where does the loan amount and insert amount comes from....

You see a lot of questions.

Can you show us your codes and what errors do you have.

ok this is my code.

ccn = New OleDbConnection(ACCESS_CONNECTION_STRING)
            ccn.Open()
            cmdsql = New OleDbCommand(loanstr, ccn)
            drloan = cmdsql.ExecuteReader()
            drloan.Read()
            Label3.Text = Format(Convert.ToDouble(drloan.Item("current_loan").ToString()))
            lblbalance.Text = Format(Convert.ToDouble(drloan.Item("current_loan").ToString()))
            ' lblbalance.Text = Format(Convert.ToDouble(lblbalance.Text - txtdeposit.Text).ToString())
            drloan.Close()
            ccn.Close()


 Private Sub btnsubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsubmit.Click

        lblbalance.Text = lblbalance.Text - txtdeposit.Text
    End Sub

bt deducted amount is nt saving as permanently as balance amount

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.