i have 2 form namely appointment and drug.
in the appointment form there is datagrid containing 2 columns namely drugname and quantityused.
in the drug form i have 2 textbox namely txtoriginal quantity and txtquantityleft..
my problem is that i want the txtquantityleft takes the originalquantity substract the quantityused column in the appointment form.


How can i do this ?
Plzz Need help...

Dani AI

Generated

laid out the situation: an Appointment page with a DataGrid (columns: drugname, quantityused) and a Drug page with txtOriginalQuantity and txtQuantityLeft. asked whether you meant a selected row; you clarified that you want the original quantity minus the used quantity to appear in txtQuantityLeft.

A safe, clear approach:

  • Identify the drug by its primary key (not just name). Pass that ID when switching pages or selecting a row.
  • Decide whether you subtract a single selected quantityused or the total used across appointments. If multiple appointments can consume the same drug, compute the SUM of QuantityUsed for that drug (recommended).
  • Retrieve original quantity from the Drugs table (or txtOriginalQuantity if already loaded), compute the subtraction server-side, and display the result in txtQuantityLeft. Validate numeric input and guard against negative values.

Example snippets (conceptual):

' SQL to calculate remaining stock (server-side)
SELECT D.OriginalQuantity - COALESCE(SUM(A.QuantityUsed),0) AS QuantityLeft
FROM Drugs D LEFT JOIN Appointments A ON A.DrugID = A.DrugID
WHERE D.DrugID = @DrugID
GROUP BY D.OriginalQuantity
' VB.NET: safe parsing and assignment
Dim orig As Integer
Dim used As Integer
If Integer.TryParse(txtOriginalQuantity.Text, orig) AndAlso Integer.TryParse(strUsed, used) Then
    txtQuantityLeft.Text = (orig - used).ToString()
End If

Notes: pass the drug ID via query string, Session, or cross-page postback; prefer server-side calculation to avoid client tampering; validate and handle concurrency (update stock in DB within a transaction or recalc from DB when saving appointments). , since you uploaded the project, focus on using the drug ID and server-side SUM to keep txtQuantityLeft accurate.

Recommended Answers

All 5 Replies

u means selected quantityUsed row in datagrid will appear in txtquantityleft on other form?

no selected quantity used will dbe deducted from original quantity on other form. then the quantityleft will show me the answer..

here is a sample of my project

drug form

Hi i have post my project can u have a look ?

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.